typelevel / typelevel/cats

Add missing semi-/sub-/-F/-Tap versions of flatMap to monad transformers

Open
#2,440 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

Monad transformers lack some semi-/sub-/-F/-Tap versions of flatMap that free a user from manual lifting or mapping.

I find the following items reasonable for implementation as to make structures and transformers more consistent:

  • OptionT:
    • add member methods flatTap, flatTapF, semiflatTap, subflatTap
  • Either:
    • add extensions flatTap, leftFlatTap to EitherOps syntax class
  • EitherT:
    • add member methods leftFlatMapF, leftSubflatMap
    • add member methods flatTap, flatTapF, semiflatTap, subflatTap
    • add member methods leftFlatTap, leftFlatTapF, leftSemiflatTap, leftSubflatTap
    • add member methods biSemiflatTap
  • Ior:
    • add member methods leftFlatMap
    • add member methods flatTap, leftFlatTap
  • IorT:
    • add member methods leftFlatMapF, leftSubflatMap
    • add member methods flatTap, flatTapF, semiflatTap, subflatTap
    • add member methods leftFlatTap, leftFlatTapF, leftSemiflatTap, leftSubflatTap
  • IdT:
    • add member methods flatTap, flatTapF
  • WriterT:
    • add member methods flatMapF, semiflatMap, subflatMap
    • add member methods flatTap, flatTapF, semiflatTap, subflatTap
  • Kleisli:
    • add member methods flatTap, flatTapF
  • IndexedStateT:
    • add member methods flatTap, flatTapF
  • IndexedReaderWriterStateT:
    • add member methods flatTap, flatTapF

Open questions:

  • flatTap automatically comes from FlatMap syntax. For some transformers it has a special implementation (e.g. for EitherT), for others it is standard (e.g. for OptionT). Should we add it to the latter for symmetry and consistency? (Added)
  • EitherT has biSemiflatMap. Do Either/EitherT/Ior/IorT need biFlatMap with all the semi-/sub-/-F/-Tap versions?

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 by reviewing the existing flatMap, biSemiflatMap, and related semi-/sub-/-F/‑Tap APIs across Either, EitherT, Ior, and IorT. The listed implementation items are marked complete, so the remaining work is to determine whether biFlatMap and its variants are needed and define what completion means before changing the transformer APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.