Skip to content

Commit dfbd0d6

Browse files
committed
Currying Functions in scala
1 parent ab272c4 commit dfbd0d6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Functions/Currying.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Currying is taking a set of arguments and turning them into sequence of functions returning functions.
3+
* You can convert a function into a currying function by calling curried on that function.
4+
* Use Funtion.uncurried to uncurry a function.
5+
* Currying is named after mathematician Haskel Curry.
6+
*/
7+
8+
object Currying extends App{
9+
val g = (x:Int) => (y:Int) => x + y //here g is a function which returns a function with returns Int
10+
11+
val f = (x:Int, y:Int) => x + y
12+
13+
val fc = f.curried //fc and g are the same functions
14+
15+
val fuc = Function.uncurried(fc)
16+
17+
println("fuc(4, 5) : " +fuc(4, 5))
18+
}
19+
20+
/**
21+
Sample Output
22+
fuc(4, 5) : 9
23+
*/

0 commit comments

Comments
 (0)