reduce-while

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
2 KB
Like [`reduce`](#reduce), `reduceWhile` returns a single item by iterating through the list, successively calling the iterator function.
1 contributor
Install reduce-while as a package?
Copied
npm i @bit/justin-capalbo.ramda.reduce-while
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
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
const isOdd = (acc, x) => x % 2 === 1;
     const xs = [1, 3, 5, 60, 777, 800];
     R.reduceWhile(isOdd, R.add, 0, xs); //=> 9

     const 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.

Help and resources