arrow-core icon indicating copy to clipboard operation
arrow-core copied to clipboard

["Request"] Either: Side effect (foreach) running

Open mkotsbak opened this issue 5 years ago • 1 comments
trafficstars

What version are you currently using? 0.11.0

What would you like to see? Side effect running from Either, instead of misusing map/flatMap without return value. Similar to Either.foreach in Scala std. lib: https://www.scala-lang.org/api/2.12.0/scala/util/Either.html#foreachU:Unit

Btw: https://github.com/typelevel/cats/issues/2193 Is there any better alternative using Arrow?

mkotsbak avatar Sep 21 '20 14:09 mkotsbak

Hey @mkotsbak,

We didn't any of these patterns because they typically violate the rules of referential transparency, and for such things you should use IO. However since IO is replaced with suspend and we can do effect mixing instead of effect stacking it's possible to mix suspned with inline fun Either<A, B>.foreach(f: (A) -> Unit): Unit in a referential transarent.

We're working hard atm to make Arrow Core a real core FP library. So I'm not sure if we'll add something like that in the future. There is couple alternatives atm but the simplest atm is probably either.orNull()?.let { f(it) }.

nomisRev avatar Feb 09 '21 13:02 nomisRev