11. Compositionとは?pipe()を実装する
シェアしよう
簡単 - accepted / - tried
Compositionとは?実は難しくない、@dan_abramov の説明を見ればわかります。
pipe()
を実装してください。
例えこちらの演算関数
const times = (y) => (x) => x * yconst plus = (y) => (x) => x + yconst subtract = (y) => (x) => x - yconst divide = (y) => (x) => x / y
pipe()
を使って、新しい演算関数を作れることになる
pipe([ times(2), times(3)]) // x * 2 * 3pipe([ times(2), plus(3), times(4)]) // (x * 2 + 3) * 4pipe([ times(2), subtract(3), divide(4)]) // (x * 2 - 3) / 4
補足
pipe()
に渡す関数の引数は一つしかないと想定して良い