Skip to content

Instantly share code, notes, and snippets.

@izmailoff
Created September 29, 2016 05:59
Show Gist options
  • Save izmailoff/2690445040007010b64610665699e59e to your computer and use it in GitHub Desktop.
Save izmailoff/2690445040007010b64610665699e59e to your computer and use it in GitHub Desktop.
One of the ways to compose functions
val add1 = (x: Int) => x + 1
val add100 = (x: Int) => x + 100
val square = (x: Int) => x * x
val allFunctions = List(add1, add100, square)
List(1, 2, 3) map ( allFunctions reduce (_ andThen _) )
// ((1 + 1) + 100) ^ 2 = 102^2 = 10404
//> List(10404, 10609, 10816)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment