How to use the scan function from ramda

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

1
2
3
4
5
6
7
8
9
10
11
const { SCORE, NodeResult } = require("./datastructures")


// :: (Node -> NodeResult) -> [Node] -> [NodeResult]
const mapWithPruning = evaluateFn => R.compose(
  R.tail,
  R.scan((prevNodeResult, currNode) => {
    const shouldCutOff = (prevNodeResult && (currNode.isMax && prevNodeResult.score === SCORE.WIN))
    if (shouldCutOff) {
      return NodeResult(currNode.field.slot, SCORE.UNKNOWN, currNode.isMax, undefined, currNode.depth)
    }
fork icon1
star icon3
watch icon0

21
22
23
24
25
26
27
28
29
30
31
 * R.find...
 * R.forEach
 * R.groupBy, R.groupWith
 * R.map, R.mapAccum, R.mapAccumRight
 * R.reduce...
 * R.scan
 */


// https://ramdajs.com/docs/#update
console.log('\n=== update ===');
fork icon0
star icon0
watch icon0

+ 2 other calls in file

4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
 * @param {Array} list The list to iterate over.
 * @return {Array} A list of all intermediately reduced values.
 * @example
 *
 *      var numbers = [1, 2, 3, 4];
 *      var factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24]
 */
var scan = _curry3(function scan(fn, acc, list) {
    var idx = 0;
    var len = list.length;
fork icon0
star icon0
watch icon0

+ 17 other calls in file

12478
12479
12480
12481
12482
12483
12484
12485
12486
* @return {Array} A list of all intermediately reduced values.
* @see R.reduce, R.mapAccum
* @example
*
*      const numbers = [1, 2, 3, 4];
*      const factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24]
* @symb R.scan(f, a, [b, c]) = [a, f(a, b), f(f(a, b), c)]
*/

fork icon0
star icon0
watch icon2

+ 7 other calls in file

19
20
21
22
23
24
25
26
27
28
  const list = R.takeLastWhile(isIncluded, acc)

  return R.append(next, list)
}

const windows = R.scan(winFor, [], log)

let win
while (win = windows.shift()) { // eslint-disable-line
  if (win.length > limit) {
fork icon0
star icon0
watch icon0

9
10
11
12
13
14
15
16
17
18
19
20
)


const indices = R.map(R.compose(R.nth, R.dec), [20, 60, 100, 140, 180, 220])


const registerValues = R.compose(
  R.scan((acc, value) => value(acc), 1),
  R.flatten,
  R.map(parseInstruction)
)(content)

fork icon0
star icon0
watch icon0

34
35
36
37
38
39
40
41
42
43
44
  R.chain(R.converge(R.times, [R.compose(R.always, R.head), R.last])),
  R.map(R.compose(R.over(lastLens, Number), R.split(' ')))
)(content)


const moveRopeKnots = R.curry((rope, direction) => R.converge(
  R.scan((acc, knot) => R.when(
      R.compose(R.lt(Math.sqrt(2)), distanceBetweenPoints(acc)), 
      R.converge(move, [R.compose(vectorComponentCap, R.flip(vectorBetween)(acc)), R.identity])
    )(knot)
  ), [R.compose(move(direction), R.head), R.tail])(rope)
fork icon0
star icon0
watch icon0

+ 3 other calls in file

Other functions in ramda

Sorted by popularity

function icon

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