[Repo Assist] feat: add fold, foldBack, find, tryFind, pick, tryPick, filter, choose, partition, scan, indexed, unzip, pairwise, groupBy, max, min to NonEmptyList#259
Merged
gdziadkiewicz merged 8 commits intoMay 16, 2026
Conversation
…can, indexed, unzip, pairwise, groupBy, max, min to NonEmptyList (addresses #174) Add 14 missing standard List-equivalent functions to the NonEmptyList module: - fold/foldBack: thread accumulator through the list - find/tryFind: search for elements by predicate - filter/choose: return plain 'T list (result can be empty) - partition: split into two plain lists by predicate - scan: return NonEmptyList<'State> (always non-empty) - indexed: return NonEmptyList<int * 'T> - unzip: split NonEmptyList<'T1 * 'T2> into two NonEmptyLists - pairwise: return ('T * 'T) list (may be empty for singleton) - groupBy: return NonEmptyList<'Key * NonEmptyList<'T>> - max/min: safe since list is always non-empty Functions that preserve non-emptiness return NonEmptyList. Functions that may produce empty results return plain 'T list. Add 16 property-based tests covering all new functions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
approved these changes
May 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fills a long-standing API gap by adding missing List-equivalent operations to NonEmptyList, while preserving the design rule that only operations guaranteed to stay non-empty return NonEmptyList<_>.
Changes:
- Added 14
List-equivalent functions tosrc/FSharpx.Collections/NonEmptyList.fs(e.g.,fold,find,filter,scan,groupBy,max/min). - Added property-based tests to validate behavior matches
Listequivalents intests/FSharpx.Collections.Tests/NonEmptyListTests.fs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/FSharpx.Collections/NonEmptyList.fs | Adds missing List-equivalent functions to NonEmptyList with appropriate return types (non-empty vs possibly empty). |
| tests/FSharpx.Collections.Tests/NonEmptyListTests.fs | Adds property-based tests comparing new NonEmptyList functions against List behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/fsprojects/FSharpx.Collections/sessions/39b07b94-77df-4c26-a1a3-3f60bc9bf510 Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharpx.Collections/sessions/0ab0d5a4-394b-4f6b-81e4-432a957cf790 Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com>
…-88c4374885613a30
Agent-Logs-Url: https://github.com/fsprojects/FSharpx.Collections/sessions/32ec970f-6cf2-4304-b696-d5b29b5f47cf Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharpx.Collections/sessions/32ec970f-6cf2-4304-b696-d5b29b5f47cf Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com>
…-88c4374885613a30
gdziadkiewicz
approved these changes
May 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Closes #174
Summary
Adds 16 missing standard
List-equivalent functions to theNonEmptyListmodule, addressing the long-standing gap identified in #174.Functions Added
fold'StateList.foldfoldBack'StateList.foldBackfind'TKeyNotFoundExceptionif not foundtryFind'T optionSome xfor the first element where predicate returnstrue;Noneif none matchpick'UKeyNotFoundExceptionif chooser never returnsSometryPick'U optionSomeresult from chooser, orNonefilter'T listchoose'U listpartition'T list * 'T listindexedNonEmptyList<int * 'T>unzipNonEmptyList<'T1> * NonEmptyList<'T2>pairwise('T * 'T) listscanNonEmptyList<'State>groupByNonEmptyList<'Key * NonEmptyList<'T>>max'Tmin'TDesign principle: functions that cannot produce an empty result return
NonEmptyList<_>; functions that can produce an empty result return a plain'T list.Tests
18 property-based tests added to
NonEmptyListTests.fs, verifying consistency withListmodule equivalents.Test Status
✅ All tests pass on ubuntu-latest via
dotnet test. Fantomas formatting check passes.