Skip to content

Expand Foldable docs: add sections for collectFirst, findM, foldMapA/M/K, minimumByList, partitionEither#4827

Open
arnavsharma990 wants to merge 1 commit intotypelevel:mainfrom
arnavsharma990:docs/expand-foldable-page
Open

Expand Foldable docs: add sections for collectFirst, findM, foldMapA/M/K, minimumByList, partitionEither#4827
arnavsharma990 wants to merge 1 commit intotypelevel:mainfrom
arnavsharma990:docs/expand-foldable-page

Conversation

@arnavsharma990
Copy link
Contributor

@arnavsharma990 arnavsharma990 commented Feb 20, 2026

Motivation

The Foldable docs page (docs/typeclasses/foldable.md) was only 138 lines and covered only the most basic methods despite Foldable having grown a rich API over several releases. Many commonly-used methods had zero documentation outside their Scaladoc.

Changes

Adds 7 new sections with prose explanations and runnable mdoc examples:

  • collectFirst / collectFirstSome — short-circuiting search via PartialFunction or A => Option[B]
  • collectFold / collectFoldSome — filtered fold accumulating into a Monoid
  • findM — monadic short-circuiting find with an effectful predicate
  • foldMapM / foldMapA — fold-map in a Monad / Applicative context, with a note on the short-circuiting difference
  • foldMapK — fold-map via MonoidK
  • minimumByList / maximumByList — collect all tied minimum/maximum elements
  • partitionEither — split a structure into two collections via Either

…M/K, minimumByList, partitionEither

The Foldable docs page covered only the most basic methods despite Foldable
having grown a rich API over several releases. This adds dedicated sections
with prose explanations and runnable mdoc examples for:

  - collectFirst / collectFirstSome  (PartialFunction / Option-based search)
  - collectFold / collectFoldSome    (filtered fold to Monoid)
  - findM                            (monadic short-circuiting find)
  - foldMapM / foldMapA              (fold-map in Monad / Applicative context)
  - foldMapK                         (fold-map via MonoidK)
  - minimumByList / maximumByList    (all tied minimum/maximum elements)
  - partitionEither                  (split structure by Left/Right)
Copilot AI review requested due to automatic review settings February 20, 2026 09:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request expands the Foldable typeclass documentation by adding comprehensive coverage of 7 commonly-used but previously undocumented methods. The additions follow the established mdoc documentation pattern, providing clear prose explanations followed by executable code examples.

Changes:

  • Added documentation sections for collectFirst/collectFirstSome, collectFold/collectFoldSome, findM, foldMapM/foldMapA, foldMapK, minimumByList/maximumByList, and partitionEither
  • Each section includes practical examples demonstrating the methods' behavior and use cases
  • All examples are formatted as mdoc code blocks that will be validated during documentation build

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +196 to +197
in `Option`). `foldMapA` is the `Applicative` variant — it cannot short-circuit but
works in a broader set of contexts.
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement "it cannot short-circuit" is too strong. While foldMapA does not guarantee short-circuiting behavior (unlike foldMapM which guarantees it via the Monad constraint), some Applicative instances like Option do actually short-circuit. The current wording could mislead readers into thinking foldMapA will never short-circuit.

Consider rewording to something like: "foldMapA is the Applicative variant — it does not guarantee short-circuiting (though some Applicative instances like Option do), but works in a broader set of contexts."

Alternatively, since the example at line 208 already mentions "foldMapA behaves the same for Option", you could simply say "foldMapA is the Applicative variant — it works in a broader set of contexts but may not short-circuit for all Applicative instances."

Suggested change
in `Option`). `foldMapA` is the `Applicative` variant — it cannot short-circuit but
works in a broader set of contexts.
in `Option`). `foldMapA` is the `Applicative` variant — it works in a broader set of
contexts but may not short-circuit for all `Applicative` instances.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants