In Scala there's the notion of a "partial function" that is fairly similar to what F#'s function keyword allows me to achieve. However Scala's partial functions also allow for composition via the orElse method as shown below:
def intMatcher: PartialFunction[Any,String] = {
case _ : Int => "Int"
}
def stringMatcher: PartialFunction[Any,String] = {
case _: String => "String"
}
def defaultMatcher: PartialFunction[Any,String] = {
case _ => "other"
}
val msgHandler =
intMatcher
.orElse(stringMatcher)
.orElse(defaultMatcher)
msgHandler(5) // yields res0: String = "Int"
I need to know if there's a way to achieve the same composition functionality in F#.