Created
January 24, 2018 08:02
-
-
Save ryu1-1uyr/95c04ee4a1e33638b29f8a787a91b67f to your computer and use it in GitHub Desktop.
関数型で書きたい 自分の解釈でコメントアウト(間違ってるかもしれない)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const curry = fn => (...args) => fn.bind(null, ...args); | |
const curryOne = fn => x =>fn(x); //引数の数を無視して、1つ目の引数を持ってくる | |
const _compose = (f, g) => (x) => f(g(x)); //2つの関数を実行g => fの順番 | |
const compose = (...fs) => fs.reduce(_compose); //n個の関数を実行する 後ろから実行する(_composeを多様化させた) | |
const pipe = (...fs) => fs.reduceRight(_compose); | |
const p = console.log; | |
const double = (x) => x * 2; | |
p(double(double(3))); // => 12 | |
_compose(p,double(2)); // =>実行されない・・・ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
double(2) は function ではなくて value よって_composeが受けられない
下記のいづれかの書き方
_compose(p, double)(double(3));
_compose(p, _compose(double,double))(3);
compose(p, double, double)(3);