Expand Foldable docs: add sections for collectFirst, findM, foldMapA/M/K, minimumByList, partitionEither#4827
Conversation
…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)
There was a problem hiding this comment.
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, andpartitionEither - 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.
| in `Option`). `foldMapA` is the `Applicative` variant — it cannot short-circuit but | ||
| works in a broader set of contexts. |
There was a problem hiding this comment.
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."
| 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. |
Motivation
The
Foldabledocs page (docs/typeclasses/foldable.md) was only 138 lines and covered only the most basic methods despiteFoldablehaving 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
mdocexamples:collectFirst/collectFirstSome— short-circuiting search viaPartialFunctionorA => Option[B]collectFold/collectFoldSome— filtered fold accumulating into aMonoidfindM— monadic short-circuiting find with an effectful predicatefoldMapM/foldMapA— fold-map in aMonad/Applicativecontext, with a note on the short-circuiting differencefoldMapK— fold-map viaMonoidKminimumByList/maximumByList— collect all tied minimum/maximum elementspartitionEither— split a structure into two collections viaEither