You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1 KiB

4 years ago
  1. # cumpa
  2. Minimal function composition implementation
  3. <img alt="cumpa" src="./cumpa.gif" width="50%"/>
  4. > `cumpá` in some Italian :it: dialects means `fellow`
  5. [![Build Status][travis-image]][travis-url]
  6. [![NPM version][npm-version-image]][npm-url]
  7. [![NPM downloads][npm-downloads-image]][npm-url]
  8. [![MIT License][license-image]][license-url]
  9. ## Usage
  10. ```js
  11. import compose from 'cumpa'
  12. const add2 = x => x + 2
  13. const multiplyBy3 = x => x * 3
  14. const add2AndMultiplyBy3 = compose(multiplyBy3, add2)
  15. console.log(add2AndMultiplyBy3(1)) // ((1 + 2) * 3) = 9
  16. ```
  17. [travis-image]: https://img.shields.io/travis/GianlucaGuarini/cumpa.svg?style=flat-square
  18. [travis-url]: https://travis-ci.org/GianlucaGuarini/cumpa
  19. [license-image]: http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
  20. [license-url]: LICENSE
  21. [npm-version-image]: http://img.shields.io/npm/v/cumpa.svg?style=flat-square
  22. [npm-downloads-image]: http://img.shields.io/npm/dm/cumpa.svg?style=flat-square
  23. [npm-url]: https://npmjs.org/package/cumpa
  24. ## API
  25. <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
  26. #### Table of Contents
  27. - [composeRight](#composeright)
  28. - [Parameters](#parameters)
  29. - [compose](#compose)
  30. - [Parameters](#parameters-1)
  31. ### composeRight
  32. Similar to compose but performs from left-to-right function composition.<br/>
  33. [see also](https://30secondsofcode.org/function#composeright)
  34. #### Parameters
  35. - `fns` **...\[[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)]** ) - list of unary fynctions
  36. Returns **any** result of the computation
  37. ### compose
  38. Performs right-to-left function composition.
  39. Use Array.prototype.reduce() to perform right-to-left function composition.
  40. The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.<br/>
  41. [source code](https://30secondsofcode.org/function#compose)
  42. #### Parameters
  43. - `fns` **...\[[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)]** ) - list of unary fynctions
  44. Returns **any** result of the computation