How to use the unfold function from ramda

Find comprehensive JavaScript ramda.unfold code examples handpicked from public code repositorys.

130
131
132
133
134
135
136
137
138
139
140
141


const transduce = _.transduce(
    _.compose(_.map(square), _.filter(isOdd)), // transducer
    _.add, // reducer function
    0, // initial value
    _.unfold((num) => num >= 10 ? false : [num, num + 1], 1) //  lazy iteration
)


console.log('transduce=', transduce)

fork icon1
star icon2
watch icon0

4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
 * @param {*} seed The seed value.
 * @return {Array} The final list.
 * @example
 *
 *      var f = n => n > 50 ? false : [-n, n + 10];
 *      R.unfold(f, 10); //=> [-10, -20, -30, -40, -50]
 */
var unfold = _curry2(function unfold(fn, seed) {
    var pair = fn(seed);
    var result = [];
fork icon0
star icon0
watch icon0

+ 17 other calls in file

183
184
185
186
187
188
189
190
191
192
    return [[chrom1M, chrom2M], pop__]
  }, population))
  
  return step(newPopulation, n + 1)
}
// const finalPopulation = R.unfold(step, initialPopulation)
// const finalPopulation = R.reduceRight(step, _ => [], R.range(0, maxSteps))(initialPopulation)
const finalPopulation = step(initialPopulation, 0)

const best = R.compose(
fork icon0
star icon0
watch icon0

+ 2 other calls in file

14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
 * @return {Array} The final list.
 * @example
 *
 *      const f = n => n > 50 ? false : [-n, n + 10];
 *      R.unfold(f, 10); //=> [-10, -20, -30, -40, -50]
 * @symb R.unfold(f, x) = [f(x)[0], f(f(x)[1])[0], f(f(f(x)[1])[1])[0], ...]
 */




var unfold =
fork icon0
star icon0
watch icon2

+ 7 other calls in file

30
31
32
33
34
35
36
37
38
39
40
      R.map(R.compose(
          R.assocPath(R.__, 1, {}),
          R.map(R.toString))),


      R.append(end),
      R.unfold((pos) => {
        if (R.equals(pos, end)) return false;
        return [pos, R.zipWith(R.add, pos, direction)];
      }))(start);
};
fork icon0
star icon0
watch icon0

25
26
27
28
29
30
31
32
33
34
  let nextAcc = acc + newCoin.value;
  return acc > target + partialFee ? false : [[nextAcc, partialFee, newCoin], [nextAcc, partialFee, restCoins]];
};
let partialFee = transactionBytes([], targets) * feePerByte;
let effectiveCoins = filter(c => Coin.effectiveValue(feePerByte, c) > 0, coins);
let selection = unfold(_findTarget, [0, partialFee, effectiveCoins]);
if (isEmpty(selection)) {
  // no coins to select
  return { fee: 0, inputs: [], outputs: [] };
} else {
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)