Skip to content

Instantly share code, notes, and snippets.

@Krasnyanskiy
Last active April 21, 2016 11:07
Show Gist options
  • Save Krasnyanskiy/95fac47c3e2b5e0b1d2ea9fbb6871ca3 to your computer and use it in GitHub Desktop.
Save Krasnyanskiy/95fac47c3e2b5e0b1d2ea9fbb6871ca3 to your computer and use it in GitHub Desktop.
-scala: function composing
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