Quantcast
Channel: Day to day stuff
Viewing all articles
Browse latest Browse all 83

Avoiding Scala's Option.fold

$
0
0
Scala's Option.fold is a bit nasty to use sometimes because type inference is not always great. Here is a stupid toy example: val someValue: Option[String] = ??? val processed = someValue.fold[Either[Error, UserName]]( Left(Error("No user name given")) )( value => Right(UserName(value)) ) The [Either[Error, UserName]] on fold is necessary otherwise the scala compiler can not derive the

Viewing all articles
Browse latest Browse all 83

Trending Articles