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 -
If you need more convincing, spot the bug here: for { x <- Try(something) x2 <- someOperation(x) x3 <- andAnotherOne(x2) x4 <- somethingElse(x3) x5 <- methodApp(x3) x6 <- oneLastThing(x4) } yield x6 I know it was easy, but *only* because you were looking!
1 reply 2 retweets 10 likesShow this thread -
Replying to @propensive
A properly typed program would make more sense for this, surely
2 replies 0 retweets 2 likes -
Replying to @noelmarkham @propensive
Or even using >>= in this instance: Try(something) >>= someOperation >>= andAnotherOne...
1 reply 0 retweets 0 likes
The combinators are nice (if you have them, of course!) though in a typical usage, I might have other assignments (flatMaps/maps) woven between those xs, so it's not so general.
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.