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.
-
-
Replying to @propensive
fold does not play nicely with type inference @ Some(1).fold(Nil)(_ :: Nil) found : List[Int] required: scala.collection.immutable.Nil.type val res0 = Some(1).fold(Nil)(_ :: Nil) ^
2 replies 0 retweets 7 likes -
Replying to @olafurpg
Well... if you do have a `Some`! But that would seem like a potential error anyway, and there would be an equivalent error in the `match` alternative.
1 reply 0 retweets 2 likes -
Replying to @propensive @olafurpg
what does Some have anything to do with it not lubbing the two alternative result types?
1 reply 0 retweets 0 likes -
I mean, if you statically know it's a Some, you can statically .get it. Or am I missing something?
1 reply 0 retweets 0 likes -
Replying to @propensive @olafurpg
you're missing that that's not the "not play nicely" Olaf means. scala> Option(1).fold(Nil)(_ :: Nil) <console>:12: error: type mismatch; found : List[Int] required: scala.collection.immutable.Nil.type Option(1).fold(Nil)(_ :: Nil) ^
2 replies 0 retweets 0 likes -
Ah, yes I was! (Fixed in Dotty, though. :) )
1 reply 0 retweets 2 likes -
This Tweet is unavailable.
-
There is no cata in cats is there?
0 replies 0 retweets 1 like -
This Tweet is unavailable.
At last, a popular culture reference I get!
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.