0.0.1 • Published 5 years ago

@sullux/fp-light-collect v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

home

fp-light-collect

npm i @sullux/fp-light-collect source test

The collect utility creates a function that accepts n arguments and passes them to the wrapped function in a single array argument.

collect

collect<T>(fn: (Array<mixed>) => T): (...args: Array<mixed>) => T

While this utility doesn't do a complex job, it can help make some functional programming more readable as in the following example.

const { collect } = require('@sullux/fp-light-collect')
const { reduce } = require('@sullux/fp-light-reduce')

const callInOrder = collect(reduce(
  (result, next) => next(result),
  undefined,
))

callInOrder(
  () => console.log('starting'),
  () => 40 + 2,
  value => console.log('ended with', value)
)
/*
starting
ended with 42
*/

This example collects functions and passes them to a pipe-like reducer.