Skip to content

Instantly share code, notes, and snippets.

@gustavofranke
Last active August 21, 2018 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavofranke/de2470323644c616c3db4301c796a369 to your computer and use it in GitHub Desktop.
Save gustavofranke/de2470323644c616c3db4301c796a369 to your computer and use it in GitHub Desktop.
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
@gustavofranke
Copy link
Author

very nice to see how Function1 forms a monoid with e = identity and op = andThen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment