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

Lint for .flatTap with non-Unit result #43

Open
armanbilge opened this issue Jul 16, 2022 · 0 comments
Open

Lint for .flatTap with non-Unit result #43

armanbilge opened this issue Jul 16, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@armanbilge
Copy link
Member

armanbilge commented Jul 16, 2022

flatTap is defined as:

def flatTap[A, B](fa: F[A])(f: A => F[B]): F[A] =
  flatMap(fa)(a => as(f(a), a))

https://github.com/typelevel/cats/blob/fbad4be326cb1a244bfae14db43e06cc486aa602/core/src/main/scala/cats/FlatMap.scala#L172-L173

While silently discarding an arbitrary B is convenient for ergonomics, it may be desirable to call attention to the fact you are discarding a result by requiring that B =:= Unit and thus forcing the user to call .void if their function does not return F[Unit].

This seems like a good candidate for a lint. Inspired by a Discord question, h/t @sbuzzard.

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