Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val plus012 = Array((_: Int) + 0,
(_: Int) + 1,
(_: Int) + 2)
/* plus012.apply(1) で (_: Int) + 1 を取り出して、2 を渡す */
plus012(1)(2) // 3
/* SeqがPartialFunction[Int, A]を継承しているので orElseを呼べる
* plus: PartialFunction[Int, (Int) => Int] */
val plus = plus012.orElse[Int, Int => Int] { case i => (_: Int) + i }
plus(3)(4)
// 7
/* Array[Int => Int] を Int => Int => Int だとみなして、アンカリー化
* plusFunc: (Int, Int) => Int */
val plusFunc = Function.uncurried(plus012)
plusFunc(1, 2)
// 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.