typelevel / typelevel/cats

Deprecate foreach in API

Open
#2,193 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

On principle, Cats has not provided foreach methods for most of its datatypes as this method implies side-effects. To be consistent, the following methods should be marked deprecated, documenting the suggested workarounds of either:

  • using IO.traverse or
  • using alleycats foreach additions to Foldable
core/src/main/scala/cats/data/Ior.scala
84:  final def foreach(f: B => Unit): Unit = {

core/src/main/scala/cats/data/Validated.scala
31:  def foreach(f: A => Unit): Unit = this match {

core/src/main/scala/cats/syntax/either.scala
38:  def foreach(f: B => Unit): Unit = eab match {

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 listed foreach methods in core/src/main/scala/cats/data/Ior.scala, core/src/main/scala/cats/data/Validated.scala, and core/src/main/scala/cats/syntax/either.scala. Review the surrounding API and deprecation conventions, then verify that each method documents IO.traverse or alleycats foreach as the suggested workaround and that the affected Scala tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.