scala - Pattern Matching on Disjunction -


given following:

scala> val err: \/[string, boolean \/ int] = -\/("bad") err: scalaz.\/[string,scalaz.\/[boolean,int]] = -\/(bad) 

i wrote function takes \/[string, boolean \/ int] , returns boolean \/ int:

scala> def f(x: \/[string, boolean \/ int]): \/[boolean, int] = x match {      |       case -\/(_) => -\/(false)      |       case \/-(y) => y      | } f: (x: scalaz.\/[string,scalaz.\/[boolean,int]])scalaz.\/[boolean,int] 

it appears work expected:

scala> f(err) res6: scalaz.\/[boolean,int] = -\/(false)  scala> f(\/-(\/-(5))      | ) res7: scalaz.\/[boolean,int] = \/-(5) 

is there more concise, idiomatic scalaz way this?

def f(x: \/[string, boolean \/ int]) = x.getorelse(-\/(false)) 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -