Share your code. Components are building blocks, you are the architect.

utils/reduce-while
v1.1.0
1.1.0
1.0.0
MIT
PUBLIC
3
Build: fail
BuildFail
Build Status: fail
Like [`reduce`](#reduce), `reduceWhile` returns a single item by iterating

Please configure Bit as a scoped registry to install components with NPM.Learn more

npm config set '@bit:registry' https://node.bitsrc.io
Use utils/reduce-while in your project
npm i @bit/bit.ramda.utils.reduce-while
Copied

reduceWhile (pred:Function, fn:Function, a:*, list:Array) : *

Like reduce, reduceWhile returns a single item by iterating through the list, successively calling the iterator function. reduceWhile also takes a predicate that is evaluated before each step. If the predicate returns false, it “short-circuits” the iteration and returns the current value of the accumulator.

Example

var isOdd = (acc, x) => x % 2 === 1;
     var xs = [1, 3, 5, 60, 777, 800];
     R.reduceWhile(isOdd, R.add, 0, xs); //=> 9

     var ys = [2, 4, 6]
     R.reduceWhile(isOdd, R.add, 111, ys); //=> 111

Arguments

pred: Function

The predicate. It is passed the accumulator and the current element.

fn: Function

The iterator function. Receives two values, the accumulator and the current element.

a: *

The accumulator value.

list: Array

The list to iterate over.

Returns

*

The final, accumulated value.