Created
October 9, 2013 18:15
-
-
Save spoertsch/6905678 to your computer and use it in GitHub Desktop.
IPSWAYS Scala Meetup - Partial function vs. Currying
This file contains 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 lessThan(max: Int, value: Int) = value < max | |
//> lessThan: (max: Int, value: Int)Boolean | |
lessThan(5, 10) | |
//> res0: Boolean = false | |
// Partial applied functions | |
val lessThan5 = lessThan(max = 5, _: Int) | |
//> lessThan5 : Int => Boolean = <function1> | |
lessThan5(10) | |
//> res1: Boolean = false | |
// Curried function | |
def lessThanCurried(max: Int)(value: Int) = value < max | |
//> lessThanCurried: (max: Int)(value: Int)Boolean | |
lessThanCurried(5)(10) | |
//> res2: Boolean = false | |
val lessThan5Curried = lessThanCurried(5)_ | |
//> lessThan5Curried : Int => Boolean = <function1> | |
lessThan5Curried(10) | |
//> res3: Boolean = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment