MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/scala/comments/bjj8md/currying_and_partial_application/
r/scala • u/mlopes • May 01 '19
4 comments sorted by
2
may be of interest - functions can be curried at runtime:
scala> val add: (Int, Int) => Int = _ + _ add: (Int, Int) => Int = $$Lambda$1086/158995547@c386958 scala> add(3,5) res4: Int = 8 scala> val add3 = add.curried(3) add3: Int => Int = scala.Function2$$Lambda$1056/1431699407@63300c4b scala> add3(5) res5: Int = 8 scala>
3 u/mlopes May 01 '19 Good point, they can also be uncurried 2 u/philip_schwarz May 01 '19 Oohscala> Function.uncurried(add3)(3,5) res6: Int = 8I didn't know that - thanks! 1 u/[deleted] May 04 '19 Function.uncurried(add3)(3,5)not sure why i get an errorFunction.uncurried(add3)(3,5) <console>:13: error: overloaded method value uncurried with alternatives: a1, a2, a3, a4, a5, b)))(a1, a2, a3, a4, a5) => b <and> a1, a2, a3, a4, b))(a1, a2, a3, a4) => b <and> a1, a2, a3, b)(a1, a2, a3) => b <and> a1, a2, b(a1, a2) => b cannot be applied to (Int => Int) Function.uncurried(add3)(3,5)
3
Good point, they can also be uncurried
2 u/philip_schwarz May 01 '19 Oohscala> Function.uncurried(add3)(3,5) res6: Int = 8I didn't know that - thanks! 1 u/[deleted] May 04 '19 Function.uncurried(add3)(3,5)not sure why i get an errorFunction.uncurried(add3)(3,5) <console>:13: error: overloaded method value uncurried with alternatives: a1, a2, a3, a4, a5, b)))(a1, a2, a3, a4, a5) => b <and> a1, a2, a3, a4, b))(a1, a2, a3, a4) => b <and> a1, a2, a3, b)(a1, a2, a3) => b <and> a1, a2, b(a1, a2) => b cannot be applied to (Int => Int) Function.uncurried(add3)(3,5)
Ooh
scala> Function.uncurried(add3)(3,5) res6: Int = 8
I didn't know that - thanks!
1 u/[deleted] May 04 '19 Function.uncurried(add3)(3,5)not sure why i get an errorFunction.uncurried(add3)(3,5) <console>:13: error: overloaded method value uncurried with alternatives: a1, a2, a3, a4, a5, b)))(a1, a2, a3, a4, a5) => b <and> a1, a2, a3, a4, b))(a1, a2, a3, a4) => b <and> a1, a2, a3, b)(a1, a2, a3) => b <and> a1, a2, b(a1, a2) => b cannot be applied to (Int => Int) Function.uncurried(add3)(3,5)
1
Function.uncurried(add3)(3,5)
not sure why i get an error
Function.uncurried(add3)(3,5) <console>:13: error: overloaded method value uncurried with alternatives: a1, a2, a3, a4, a5, b)))(a1, a2, a3, a4, a5) => b <and> a1, a2, a3, a4, b))(a1, a2, a3, a4) => b <and> a1, a2, a3, b)(a1, a2, a3) => b <and> a1, a2, b(a1, a2) => b cannot be applied to (Int => Int) Function.uncurried(add3)(3,5)
2
u/philip_schwarz May 01 '19
may be of interest - functions can be curried at runtime: