web 3d图形渲染器
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.

83 lines
2.3 KiB

  1. [![Travis](https://img.shields.io/travis/stoeffel/compose-function.svg?style=flat-square)](https://travis-ci.org/stoeffel/compose-function)
  2. [![npm](https://img.shields.io/npm/v/compose-function.svg?style=flat-square)](https://www.npmjs.com/package/compose-function)
  3. [![Dependency Status](https://david-dm.org/stoeffel/compose-function.svg?style=flat-square)](https://david-dm.org/stoeffel/compose-function)
  4. [![Coveralls](https://img.shields.io/coveralls/stoeffel/compose-function.svg?style=flat-square)](https://coveralls.io/github/stoeffel/compose-function)
  5. <h1 align="center">Compose-Function</h1>
  6. <p align="center">
  7. <a href="#installation">Installation</a> |
  8. <a href="#usage">Usage</a> |
  9. <a href="#related">Related</a> |
  10. <a href="#license">License</a>
  11. <br><br>
  12. <img align="center" height="300" src="http://33.media.tumblr.com/006dfad04f93ec5b3680ec7cdae3fafa/tumblr_n8kgl18uU41qcung4o1_1280.gif">
  13. <br>
  14. <sub>logo by <a href="http://justinmezzell.tumblr.com/">Justin Mezzell</a></sub>
  15. <blockquote align="center">Compose a new function from smaller functions `f(g(x))`</blockquote>
  16. </p>
  17. Installation
  18. ------------
  19. `npm install compose-function`
  20. Usage
  21. -----
  22. ## Basic usage
  23. ```js
  24. import compose from 'compose-function';
  25. const composition = compose(sqr, add2); // sqr(add2(x))
  26. composition(2) // => 16
  27. compose(sqr, inc)(2); // => 9
  28. compose(inc, sqr)(2); // => 5
  29. ```
  30. ## with curry
  31. ```js
  32. import compose from 'compose-function';
  33. import { curry, _ } from 'curry-this';
  34. const add = (x, y) => x + y;
  35. // add(6, sqr(add(2, x)))
  36. compose(
  37. add::curry(6),
  38. sqr,
  39. add::curry(2),
  40. );
  41. // map(filter(list, even), sqr)
  42. compose(
  43. map::curry(_, sqr),
  44. filter::curry(_, even),
  45. )([1,2,3,4,5,6,7,8]) // => [4, 16, 36, 64]
  46. ```
  47. ### `::` huh?
  48. If you’re wondering what the `::` thing means, you’d better read this excellent [overview](https://github.com/jussi-kalliokoski/trine/blob/5b735cbfb6b28ae94bac0446d9ecd5ce51fb149b/README.md#why) by [@jussi-kalliokoski](https://github.com/jussi-kalliokoski) or have a look at the [function bind syntax proposal](https://github.com/zenparsing/es-function-bind).
  49. Or checkout the [curry-this docs][ct].
  50. Related
  51. ----
  52. * [curry-this][ct]
  53. License
  54. ----
  55. MIT © [Christoph Hermann](http://stoeffel.github.io)
  56. [r]: http://ramdajs.com
  57. [ct]: https://github.com/stoeffel/curry-this