Stop using, opt match { case Some(x) => f(x); case None => y } Stop using, http://opt.map (f).getOrElse(y) Use, opt.fold(y)(f) I feel like I'm very late to this party.
-
-
Honest question though: is that a proper fold? In my mind, fold is heavily linked to monoids: - takes an "empty" value - takes a merge function that's basically a monoidal append This is not what Option.fold does. Am I misunderstanding what fold is?
-
Your mixing `Foldable` (the typeclass) with the algebraic fold, the later is basically isomorphic to pattern matching. The fact that folding on a List is recursive, is incidental (because the type itself is recursive), not the opposite.
- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.