You haven't provided enough information to answer your question.
- What type does
parseCommand() return?
- What type does
calculate() return?
- Why translate to a
for comprehension? What's your goal?
Assuming that parseCommand() and calculate() return the same or compatible types, then the 1st map() and flatMap() can be translated like so:
(for {
c <- parseCommand(x)
r <- calculate(c)
} yield renderResult(c, r)
).left
.map(e => e.value)
.merge
...
The 2nd map() can't be folded in to this for because there can be only one map() per for comprehension. You could, however, turn it into its own, nested, for comprehension, but remember that it makes no difference to the compiler, so the only real reason to use for is to enhance code readability, and nested fors seldom achieve that.