typelevel / typelevel/cats

Reduce constraint for foldMapM

Open
#2,852 1 comment 0 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

Currently

def foldMapM[G[_]: Monad, A, B: Monoid](fa: F[A])(f: A => G[B]): G[B]

but as far as I can see, we can drop the Monad constraint to Applicative

def foldMapM[G[_]: Applicative, A, B: Monoid](fa: F[A])(f: A => G[B]): G[B]

For Traverse, it is easy to see why it is possible:

def foldMapM[G[_]: Applicative, A, B: Monoid](fa: F[A])(f: A => G[B]): G[B] =
  fa.traverse(f).map(fold)

for Foldable, I still think it is stack safe because it is a foldLeft with map2

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 at Foldable.foldMapM and inspect the existing foldLeft/map2 implementation, then compare it with the Traverse.foldMapM example in the issue. Done means the constraint is reduced to Applicative while the project still compiles and its relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
tooling
Issue type
Refactor
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.