"Almost" functional programming (typed for TypeScript) utils methods
Wrapping all the methods I usually put within a functional.js
file inside my projects, as node module. BTW this is a nice way to make mistake and learn more about functional programming.
$ yarn add phunctional
The library can be used both with normal JavaScript and TypeScript.
const {switchcase} = require('phunctional');
const awesomeSwitch = {
aCondition: 'some value',
anotherCondition: 'some other value'
};
const res = switchcase(awesomeSwitch)('a default value')('aCondition');
console.log(res);
// => some value
Simple
switch
but composable with object literals. It also can run a function.
Object -> Any -> String
expand
Object
: object ofcases
to analyzeAny
: default case as anything you needString
:key
to check
Returns the choosen case or the defaultCase
Classic
map
on array but without side effects.
Function -> Array
expand
Function
: function to handle themap
Array
: array of items
Returns an empy array if the array passed is not valid.
forEach
that returns a Promise and can also handle a delay between iterations.
(Array, [Number]) -> Function -> Promise
expand
-
Array
: array of items to iterate -
Number
: delay in milliseconds to run each iteration and wait -
Function
: function to handle the single item
Returns a Promise
with an array of the results of every iteration.
MIT © LasaleFamine