Skip to content

[Repo Assist] feat: add fold, foldBack, find, tryFind, filter, choose, partition, scan, indexed, unzip, pairwise, groupBy, max, min to NonEmpt [Content truncated due to length]#259

Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/improve-nonemptylist-funcs-174-88c4374885613a30
Draft

[Repo Assist] feat: add fold, foldBack, find, tryFind, filter, choose, partition, scan, indexed, unzip, pairwise, groupBy, max, min to NonEmpt [Content truncated due to length]#259
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/improve-nonemptylist-funcs-174-88c4374885613a30

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #174

Summary

Adds 14 missing standard List-equivalent functions to the NonEmptyList module, addressing the long-standing gap identified in #174.

Functions Added

Function Return Type Notes
fold 'State Left fold, like List.fold
foldBack 'State Right fold, like List.foldBack
find 'T Raises KeyNotFoundException if not found
tryFind 'T option Safe version of find
filter 'T list Returns plain list (result can be empty)
choose 'U list Filter + map; returns plain list
partition 'T list * 'T list Both halves may be empty
indexed NonEmptyList<int * 'T> Pairs each element with its index
unzip NonEmptyList<'T1> * NonEmptyList<'T2> Splits a list of pairs
pairwise ('T * 'T) list Adjacent pairs; empty for singleton
scan NonEmptyList<'State> Always non-empty (includes initial state)
groupBy NonEmptyList<'Key * NonEmptyList<'T>> Non-empty; each group is non-empty
max 'T Safe since list is always non-empty
min 'T Safe since list is always non-empty

Design principle: functions that cannot produce an empty result return NonEmptyList<_>; functions that can produce an empty result return a plain 'T list.

Tests

16 property-based tests added to NonEmptyListTests.fs, verifying consistency with List module equivalents.

Test Status

✅ All 912 tests pass (0 failures, 2 skipped) on ubuntu-latest via dotnet test. Fantomas formatting check passes.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@96b9d4c39aa22359c0b38265927eadb31dcf4e2a

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fill gap of functions between List and NonEmptyList

0 participants