0.2.0 • Published 9 years ago
immutable-math v0.2.0
immutable-math
Some mathematatics for Immutable.js for aggregations and stuff.
install
npm install immutable-mathUsage
Functions in this library use partially applied functions.
For example, one way to use average is to call it, passing in any parameters required (average requires no extra params), then call the returned function passing in your data.
const numbers = fromJS([1,1,1,5]);
return average()(numbers); // returns 2For any immutable-math functions that return an Iterable, this design of using a partially applied function allows for easy chaining by using them inside of an update() method, if your input Iterable has an update function.
return fromJS([1,1,1,5])
.update(exampleFunction()) // using an exampleFunction from immutable-math in a chain
.sort()
.toJS();You can also define a function to perform a specific operation, and use it multiple times by passing in different input data.
const numbersA = fromJS([
{num: 1},
{num: 1},
{num: 1},
{num: 5}
]);
const numbersB = fromJS([
{num: 3},
{num: 5}
]);
const averageByNum = averageBy(ii => ii.get('num'));
const averageA = numbersA.update(averageByNum); // averageA is 2
const averageB = numbersB.update(averageByNum); // averageB is 4