His tip cleans up the examples in post Chaining Partial Functions with orElse
The secret is to define the type alias
type =>?[-A, +B] = PartialFunction[A, B]. This alias may be added to Predef in the future but until it is you can add it yourself.- scala> type =>?[-A, +B] = PartialFunction[A, B]
- defined type alias $eq$greater$qmark
- scala> val i : (Any =>? Unit) = {case x:Int => println("int found")}
- i: =>?[Any,Unit] = < function1>
- scala> val j : (Any =>? Unit) = {case x:Double => println("Double found")}
- j: =>?[Any,Unit] = < function1>
- scala> val * : (Any =>? Unit) = {case x=> println("Something else found")}
- *: =>?[Any,Unit] = < function1>
- scala> (i orElse j orElse *)(1)
- int found
- scala> (i orElse j orElse *)(1.0)
- Double found
- scala> (i orElse j orElse *)(true)
- Something else found
- scala> def =>?[A, B](id : A =>? B) = id
- $eq$greater$qmark: [A,B](id: =>?[A,B])=>?[A,B]
- scala> ( =>?[Any, Unit]{case s : String => println("String found")} orElse j orElse *)("hello")
- String found