Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate and remove ifA #3889

Closed
chuwy opened this issue May 14, 2021 · 0 comments · Fixed by #3893
Closed

Deprecate and remove ifA #3889

chuwy opened this issue May 14, 2021 · 0 comments · Fixed by #3893

Comments

@chuwy
Copy link

chuwy commented May 14, 2021

I recently ran into a very dangerous bug thinking ifM and ifA have the same semantics. It can be repdocued with:

def test[F[_]: Sync] =
  Ref.of[F, Map[Boolean, Unit]](Map.empty).flatMap { ref =>
    Sync[F].pure(true).ifA(
      ref.update { c => c ++ Map(true -> ())},
      ref.update { c => c ++ Map(false -> ())}
    ) *> ref.get
  }

@ test[IO].unsafeRunSync()
res6: Map[Boolean, Unit] = Map(true -> (), false -> ())

I'd argue that we never ever ever want to use this just with IO. But it's not much better (at first glance) with other data types:

@ true.some.ifA(true.some, false.some)
res0: Option[Boolean] = Some(true)

@ true.some.ifA(true.some, none)
res1: Option[Boolean] = None

@ true.some.ifA(none, false.some)
res2: Option[Boolean] = None

I do understand now that this is an intended behavior of executing all three effects and we simply cannot do what I wanted to do with Applicative (we can though with selective functors, https://github.com/kowainik/validation-selective), but I still think the potential risk overweight the usefulness -also just grepp'ed few popular projects (doobie, http4s, fs2) and nobody uses it it seems.

Assuming the decision has been made I can create a PR deprecating it.

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

Successfully merging a pull request may close this issue.

1 participant