3 ms·
Side point, but AFIAK `fold()()` is most idiomatic in Scala.
by paulddraper 9y ago
Side point, but AFIAK `fold()()` is most idiomatic in Scala.
- Nullabillity 9y agoAnd yet, `match` is the only one that gets correct type inference. `.map(ifSome).getOrElse(ifNone)` infers the type from `ifSome`, and forces `ifNone` to conform. `.fold(ifNone)(ifSome)` infers the type from `ifNone`, and forces `ifSome` to conform. Meanwhile, `match { case Some(x) => ifSome(x); case None(x) => ifNone }` will correctly infer from both cases at once, and give you the greatest common ancestor.
- paulddraper 9y agoYeah, I agree. ¯\_(ツ)_/¯