How to convert X => Option[R] to PartialFunction[X,R]

后端 未结 3 1420
一整个雨季
一整个雨季 2020-12-17 08:40

As long as we have a PartialFunction[X,R] it\'s very easy to convert it to a function returning Option[R], e.g.

def pfToOptf[X, R](         


        
3条回答
  •  被撕碎了的回忆
    2020-12-17 09:36

    Starting Scala 2.9, Function.unlift does precisely this:

    def unlift[T, R](f: (T) => Option[R]): PartialFunction[T, R]
    

    Turns a function T => Option[R] into a PartialFunction[T, R].

提交回复
热议问题