typelevel / typelevel/typelevel-scalafix

Lint for `.flatTap` with non-`Unit` result

Open
#43 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Scala
Stars
27
Forks
8
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced FlatMap.scala definition of flatTap, then locate the repository's existing Scalafix rule and test entry points; the issue names no implementation files or tests. Done should mean detecting flatTap calls that discard a non-Unit result while allowing F[Unit] results and the explicit .void alternative.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.