Created
September 29, 2016 05:59
-
-
Save izmailoff/2690445040007010b64610665699e59e to your computer and use it in GitHub Desktop.
One of the ways to compose functions
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 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