Methods to convert an iterable to a single value of some sort.
import { generators, reducers } from 'iterablefu'
console.log(reducers.toArray(generators.range(5))) // prints [0, 1, 2, 3, 4]
Executes function fn(item, index) for each item in the iterable sequence provided.
fn
Function a function(item, index), where item is the current item in the sequence, and index is the index of the current item.iterable
Iterable the sequence of items to call fn(item, index) with.
const fn = (item, index) => console.log(`item - ${item}, index - ${index}`)
forEach(fn, [1, 2, 3]) // prints the following...
// item - 1, index - 0
// item - 2, index - 1
// item - 3, index - 2
Returns undefined
The reduce() method executes a reducer function on each element of the input iterable, resulting in a single output value.
fn
Function fn(accumulator, item) that returns the new accumulator valueaccumulator
any the initial accumulator valueiterable
Iterable the sequence to execute fn over.
const add = (a, b) => a + b
const sum = reduce(add, 0, [0, 1, 2, 3, 4]) // sum === 10
Returns any the final accumulator value
Creates an Array from the items in iterable.
iterable
Iterable the iterable to create the array from
const a = toArray(range(5)) // a is [0, 1, 2, 3, 4]
Returns Array the array