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

Add an unneeded trailing map removing macro #115

Open
KacperFKorban opened this issue Jun 25, 2024 · 0 comments
Open

Add an unneeded trailing map removing macro #115

KacperFKorban opened this issue Jun 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@KacperFKorban
Copy link
Member

We might want to provide a macro that removes the trailing map if it is unneeded. The use for it would be to make a for-comprehension style expression stack-safe, since flatMap can be (and often is) implemented in a stack-safe manner, but a map isn't. One such example is:

def loop: IO[Unit] =
  for
    _ <- putStrLn("fix this pls")
    _ <- loop
  yield ()

We might want to add a macro elimMap that would be used like so:

def loop: IO[Unit] =
  elimMap {
    for
      _ <- putStrLn("fixed")
      _ <- loop
    yield ()
  }

That will remove the trailing map call if it is unnecessary and give an error (or warning) if the map changes the result.

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

No branches or pull requests

1 participant