Created
March 22, 2019 17:45
-
-
Save Rafailong/dcb1e67c1245776c136482d3c9d49c7e to your computer and use it in GitHub Desktop.
path to fp - currying
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
// base function | |
def add(a: Int, b: Int): Int = a + b | |
// curried form | |
def addCurried(a: Int)(b: Int): Int = a + b | |
/** | |
* In scala functions have the method `curried` | |
*/ | |
val addCurriedTwo = (add _).curried | |
println(addCurriedTwo(1)(1)) // 2 |
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
val min: Int => Int => Int = x => y => if (x <= y) x else y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment