Chaining PartialFunctions with andThen in Scala

前端 未结 3 1299
暗喜
暗喜 2020-12-20 12:56

Let us reuse examples from Daily scala :

type PF = PartialFunction[Int,Int]

val pf1 : PF = {case 1 => 2}                      

val pf2 : PF = {case 2 =&         


        
3条回答
  •  悲哀的现实
    2020-12-20 13:39

    Why not simply :

    def compose[A,B,C](f: PartialFunction[A, B], g: PartialFunction[B, C]) : PartialFunction[A, C] =
    Function.unlift(f.andThen(g.lift))
    

提交回复
热议问题