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.
-
-
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!
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
This Tweet is unavailable.
-
It has to wrap the value unnecessarily, so there's a gap allocation, plus the wrappers seem like syntactic noise to me...
- Show replies
-
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.