In this lesson we'll look at how you can use Ramda's unfold function to generate a list of values based on an initial seed.
const R = require('ramda');

// if return false, then stop iteration
// [n1, n2]: n1 is the value to be added to the result array
// n2: is the value return to next iteration as a starting value
const throughNByOne = R.curry((limit, n) => n > limit ? false: [n, n + ]);
const throughNByBaseTwo = R.curry((limit, n) => n > limit ? false: [n, n * ]); const res1 = R.unfold(throughNByOne(), ); // [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
console.log(res1); const res2 = R.unfold(throughNByBaseTwo(), ); // [ 2, 4, 8, 16, 32, 64, 128, 256 ]
console.log(res2);

[Ramda] Create an Array From a Seed Value with Ramda's unfold的更多相关文章

  1. [Ramda] Create a Query String from an Object using Ramda's toPairs function

    In this lesson, we'll use Ramda's toPairs function, along with map, join, concatand compose to creat ...

  2. [Ramda] Filter an Array Based on Multiple Predicates with Ramda's allPass Function

    In this lesson, we'll filter a list of objects based on multiple conditions and we'll use Ramda's al ...

  3. [Python Cookbook] Numpy: Multiple Ways to Create an Array

    Convert from list Apply np.array() method to convert a list to a numpy array: import numpy as np myl ...

  4. JavaScript interview Question - Create a Array with two papameters without using loop!

    JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...

  5. [Javascript] Create an Array concatAll method

    In addition to flat Arrays, programmers must often deal with nested Arrays. For example let's say we ...

  6. [Ramda] Declaratively Map Data Transformations to Object Properties Using Ramda evolve

    We don't always control the data we need in our applications, and that means we often find ourselves ...

  7. [Ramda] Refactor a Promise Chain to Function Composition using Ramda

    Promise chains can be a powerful way to handle a series of transformations to the results of an asyn ...

  8. forEach 方法 (Array) (JavaScript)

    为数组中的每个元素执行指定操作. 语法 array1.forEach(callbackfn[, thisArg]) 参数 参数 定义 array1 必选.一个数组对象. callbackfn 必选.最 ...

  9. create feature from text file

    '''---------------------------------------------------------------------------------- Tool Name: Cre ...

随机推荐

  1. 【天气APP】之桌面时钟witget组件

    桌面时钟之组件开发: 整个流程例如以下: 下载地址demo:www.github.com/xufeifandj service+组件+广播进行后台实时更新时间 (一)开机广播监听开机启动service ...

  2. Java中接口继承泛型接口

    在使用Mybatis做web开发时,每一个模块的数据持久层的接口都会定义:增删改查四个方法.我想为什么不新建一个Base接口来做所有数据持久层的父接口呢? 于是,我试验了一下,建立了一个泛型接口,里面 ...

  3. 解决Keystore was tampered with, or password was incorrect

    使用签名文件keystore查看生成的数字签名中报错解决 Keystore was tampered with, or password was incorrect 这是由于android规定自己定义 ...

  4. Keepalived + Mysql 双主

    VIP 192.168.1.41 Master 192.168.1.42 Slave 192.168.1.43 .配置 yum -y install mysql-server chkconfig -- ...

  5. Oracle中暂时表空间的清理

    作者:iamlaosong Oracle暂时表空间主要用来做查询和存放一些缓冲区数据. 暂时表空间消耗的主要原因是须要对查询的中间结果进行排序.暂时表空间的主要作用: 索引create或rebuild ...

  6. iOS之StatusBar详解

    随便打开手机上的主流APP,我们不难发现它们的状态栏都是跟导航栏保持一致的背景颜色,如下图的微信和instagram: WECHAT.PNG INS.PNG 那么今天我们就来说一下StatusBar这 ...

  7. php gettext方式实现UTF-8国际化多语言(i18n)

    php gettext方式实现UTF-8国际化多语言(i18n) 一.总结 一句话总结: 二.php gettext方式实现UTF-8国际化多语言(i18n) 近 来随着i18n(国际化)的逐渐标准化 ...

  8. 对Linux下常用头文件总结

    asm.current.h    定义全局项current ,其指向结构体struct  task_struct linux/sched.h    定义结构体task_struct ,只要包含此头文件 ...

  9. iOS开发 - Quartz2D画图

    Quartz 2D简单介绍 是一个二维画图引擎,同一时候支持iOS和Mac系统 Quartz 2D能完毕的工作 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成 ...

  10. layui是什么

    layui是什么 一.总结 一句话总结:初步看起来比amazeui好看一点点.移动端显示看起来效果真心不错.还有即时聊天那个组件下载,感觉真心不错,可以多去看看. 二.Layui 1.简介 经典模块化 ...