Help us understand the problem. What is going on with this article?

カリー化関数と部分適用の使いどころを考える

複数の引数を取る関数が、以下のように特定の変数だけ変わる偏った呼ばれ方をすることが想定される場合、

someFunc(hoge,piyo,1);
someFunc(hoge,piyo,2);
someFunc(hoge,piyo,3);
someFunc(hoge,piyo,4);
someFunc(hoge,piyo,5);

こんな感じにカリー化した関数があると、
部分適用した関数を利用してすっきりと書ける。

const curriedSomeFunc = (hoge,piyo) => (num) => {
  someFunc(hoge,piyo,num);  
}
const partiallyApplied = curriedSomeFunc(hoge,piyo);
partiallyApplied(1);
partiallyApplied(2);
partiallyApplied(3);
partiallyApplied(4);
partiallyApplied(5);

普通は通常の関数のみを外部に公開するけれども、
ユースケースが明らかに偏りそうな場合はカリー化関数も併せて出してあげると親切かもしれない。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away