Last active
April 21, 2016 11:07
-
-
Save Krasnyanskiy/95fac47c3e2b5e0b1d2ea9fbb6871ca3 to your computer and use it in GitHub Desktop.
-scala: function composing
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 f: PartialFunction[Int, Boolean] = { | |
case 1 => true | |
case 2 => true | |
case 3 => true | |
} | |
val g: PartialFunction[Boolean, Int] = { | |
case true => 1 | |
case false => 2 | |
} | |
val c: Boolean => Boolean = { // NB: type is composed too: Bool -> Int -> Bool | |
f compose g // function composing | |
} | |
println { c(true) } | |
println { c(false) } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment