New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phunctional

"Almost" functional programming utils methods


Version published
Weekly downloads
138
increased by2.99%
Maintainers
1
Weekly downloads
 
Created

phunctional

npm Build Status codecov punctional

"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 phunctional

Usage

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 switch but composable with object literals. It also can run a function.

Object -> Any -> String

expand

  • Object: object of cases to analyze
  • Any: default case as anything you need
  • String: key to check

return case | defaultCase

Returns the choosen case or the defaultCase

map

Classic map on array but without side effects.

Function -> Array

expand

  • Function: function to handle the map
  • Array: array of items

return [T] | []

Returns an empy array if the array passed is not valid.

pEach

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

return Promise

Returns a Promise with an array of the results of every iteration.

License

MIT © LasaleFamine

FAQs

Package last updated on 05 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts