Shadowing in Scala's for-comprehensions is a nice feature. It has the feel of mutability, but safer, and shadowing's almost always what you want. for { x <- Try(doSomething) x <- mightFail(x) x <- returnTry(x) } yield x Unfortunately it only works with flatMaps, not maps.
-
Show this thread
-
So you can't write, for { x <- Try(doSomething) x = someValue } yield x We can rewrite that as, for { x <- Try(doSomething) x <- Success(someValue) } yield x but it's a shame we need to.
2 replies 3 retweets 7 likesShow this thread -
This Tweet is unavailable.
-
Replying to @prezcannady
It has to wrap the value unnecessarily, so there's a gap allocation, plus the wrappers seem like syntactic noise to me...
2 replies 0 retweets 0 likes
Replying to @propensive @prezcannady
s/gap/heap/
7:34 AM - 28 Mar 2018
from East Worldham, England
0 replies
0 retweets
0 likes
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.