LoginSignup
10
7

More than 5 years have passed since last update.

ramdaのpipeとcompose

Last updated at Posted at 2017-09-06

JavaScriptで関数型スタイルでプログラミングできるramdaは便利です。

よく使われる機能としてpipecomposeがあります。
両者の違いは、左から右に適用するか右から左に適用するかです。

const R = require('ramda')

const calcCompose = R.compose(Math.abs, R.add(1), R.multiply(2))

const calcPipe = R.pipe(Math.abs, R.add(1), R.multiply(2))

calcCompose(-4)
// => 7

calcPipe(-4)
// => 10
10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7