Skip to content

Instantly share code, notes, and snippets.

@ryu1-1uyr
Created January 24, 2018 08:02
Show Gist options
  • Save ryu1-1uyr/95c04ee4a1e33638b29f8a787a91b67f to your computer and use it in GitHub Desktop.
Save ryu1-1uyr/95c04ee4a1e33638b29f8a787a91b67f to your computer and use it in GitHub Desktop.
関数型で書きたい 自分の解釈でコメントアウト(間違ってるかもしれない)
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)); // =>実行されない・・・
@omas-public
Copy link

omas-public commented Jan 25, 2018

double(2) は function ではなくて value よって_composeが受けられない
下記のいづれかの書き方

_compose(p, double)(double(3));
_compose(p, _compose(double,double))(3);
compose(p, double, double)(3);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment