LoginSignup
4
4

More than 5 years have passed since last update.

部分適応とカリー化

Last updated at Posted at 2018-05-18

部分適用

部分適用とは一部の引数を固定化して新しい関数を作り出すこと

function add(a, b) {
    return a + b
}

// 部分適用
function newAdd(a) {
    return add(1, b)
}

newAdd(2) // 3

カリー化

関数を引数1つずつに分割してネストさせること
カリー化すると部分適用が簡単に出来る

// カリー化
function add(a) {
    return function(b) {
        return a + b
    }
}

add(1)(2) // 3

let newAdd = add(1)

newAdd(2) //3
4
4
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
4
4