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
↧