Created
December 28, 2019 15:52
-
-
Save kadirmalak/36bf49c1b31cf10b768b6d0d5db91de1 to your computer and use it in GitHub Desktop.
currying-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def someFunc(a: Int, b: String, c: Double) = { | |
| println("a: " + a + ", b: " + b + ", c: " + c) | |
| } | |
| someFunc(1, "str", 3.14) // we need all parameters to call it | |
| // we're turning 3-arg function into 1-arg function | |
| def someFuncCurried(a: Int, b: String) = { | |
| def temp(c: Double) = { | |
| someFunc(a, b, c) // a and b are remembered, only c is needed | |
| } | |
| temp _ | |
| } | |
| val f = someFuncCurried(1, "str") // first 2 params saved | |
| f(3.14) // now we can call using the third |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment