Last active
August 21, 2018 14:06
-
-
Save gustavofranke/de2470323644c616c3db4301c796a369 to your computer and use it in GitHub Desktop.
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
scala> def add: Int => Int => Int = (x: Int) => (y: Int) => x + y | |
add: Int => (Int => Int) | |
scala> add(3)(4) | |
res17: Int = 7 | |
scala> val a = add(3) | |
a: Int => Int = $$Lambda$1142/734729236@6e49b011 | |
scala> a(4) | |
res18: Int = 7 | |
scala> def addThree = add(3) | |
addThree: Int => Int | |
scala> def addFour = add(4) | |
addFour: Int => Int | |
scala> val b = addThree andThen addFour | |
res19: Int => Int = scala.Function1$$Lambda$1145/429018901@621392ea | |
scala> b | |
res20: Int => Int = scala.Function1$$Lambda$1145/429018901@300aa927 | |
scala> b(0) | |
res21: Int = 7 | |
scala> b(8) | |
res22: Int = 15 | |
scala> b(1) | |
res23: Int = 8 | |
scala> b(2) | |
res24: Int = 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very nice to see how
Function1
forms a monoid withe = identity
andop = andThen