Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

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

Open
mkotsbak opened this issue Sep 21, 2020 · 1 comment
Open

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

mkotsbak opened this issue Sep 21, 2020 · 1 comment

Comments

@mkotsbak
Copy link

mkotsbak commented Sep 21, 2020

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#foreach[U](f:B=%3EU):Unit

Btw: typelevel/cats#2193 Is there any better alternative using Arrow?

@nomisRev
Copy link
Member

nomisRev commented Feb 9, 2021

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) }.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants