Ways of conditionally throwing in for comprehension

#1

Hello - I have come across code like that in lines 7 and 8 in contrived example https://scastie.scala-lang.org/philipschwarz/OcLua2VcQDmqSN2XVpCqsA/1

_ = if <condition> throw <exception>

it seems to me they can be rewritten as in lines 14 and 15

if <condition> || (throw <exception>)

Agree?

#2

note that there are some answers/discussion already at https://twitter.com/philip_schwarz/status/1161715430211428352

#3

As Jon Pretty pointed out in the thread linked by @SethTisue, “Different monad-like types might implement map and withFilter in ways which cause unexpected behaviour, so in the general case, there’s no equivalence guaranteed.”

In the case of List and Future the equivalence seems to hold - here is the same example but with Future rather than List: https://scastie.scala-lang.org/philipschwarz/IdXOsIR0RkOpiD7ZwPm69A/27