ucompose
Utility for composing functions.
Installation
$ npm install --save ucompose
Basic Usage
const ucompose = ; { return a+b;} { return a*a;} { return a>100 ? ` is greater than 💯` : a;} const addThenSquareThenDecorateThenLog = ; // print 49; // print 121 is greater than 💯;
Why (another) utility for composing functions
If you are here, chances that you know what functions composition is all about are high. This small utility provides you with an intuitive way to compose your functions. If you are familiar with Ramda.js, this utily has the semantic of R.pipe since it performs a left-to-right function composition under the conditions that only the leftmost function (the first in the chain) may take any number of arguments, and the remaining functions must be unary. But where it really shines is in the fact that it gives you the ability of grouping your functions into logical units that can be composed with other functions (or logical units) later on. See examples for more information.
features
- composition of any number of functions (left-to-right evalutions)
- logical grouping of functions
Api
ucompose: (...fns) ⇒ function (...args)
- Takes functions as parameters and returns their composition
Param | Type | Description |
---|---|---|
fns | function | Array of functions |
functions to be composed |
Examples
const ucompose = ; { // at 12:00 PM }; { // buy bread} { // buy milk}// grouping `buyBread` and `buyMilk` into a logical unit called shoppingconst shopping = buyBreadbuyMik { // Gifts are highly appreciated} const yourWeekendProgram = ; // Start your weekend;