phunctional
v0.2.1
Published
"Almost" functional programming utils methods
Maintainers
Readme
"Almost" functional programming (typed for TypeScript) utils methods
Why
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.
Install
$ yarn add phunctionalUsage
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
Methods
switchcase
Simple
switchbut composable with object literals. It also can run a function.
Object -> Any -> String
Object: object ofcasesto analyzeAny: default case as anything you needString:keyto check
return case | defaultCase
Returns the choosen case or the defaultCase
map
Classic
mapon array but without side effects.
Function -> Array
Function: function to handle themapArray: array of items
return [T] | []
Returns an empy array if the array passed is not valid.
pEach
forEachthat returns a Promise and can also handle a delay between iterations.
(Array, [Number]) -> Function -> Promise
Array: array of items to iterateNumber: delay in milliseconds to run each iteration and waitFunction: function to handle the single item
return Promise
Returns a Promise with an array of the results of every iteration.
License
MIT © LasaleFamine
