[Repo Assist] feat: add exists, forall, choose to LazyList module#253
Open
github-actions[bot] wants to merge 2 commits intomasterfrom
Open
Conversation
LazyList was missing three common collection functions that are present in FSharp.Collections.List and Seq: - exists: returns true if any element satisfies the predicate (short-circuits) - forall: returns true if all elements satisfy the predicate (short-circuits) - choose: applies an option-returning function; lazily yields Some values exists and forall are strict (traverse the list up to the first match/mismatch). choose follows the same lazy evaluation pattern as filter: evaluation is deferred until the returned list is consumed. Both LazyList.fs and LazyList.fsi updated; 9 new tests added, all passing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds the missing exists, forall, and choose functions to the LazyList module to better align FSharpx.Collections with standard F# collection APIs (per #152), including public signatures and tests.
Changes:
- Added
LazyList.existsandLazyList.forallwith short-circuiting traversal semantics. - Added
LazyList.choose, producing a lazily-evaluated filtered/mappedLazyList. - Added unit tests for the new APIs (finite/empty cases plus a basic laziness scenario for
choose).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/FSharpx.Collections.Tests/LazyListTests.fs | Adds new tests for exists, forall, and choose |
| src/FSharpx.Collections/LazyList.fsi | Exposes new LazyList public signatures with XML docs |
| src/FSharpx.Collections/LazyList.fs | Implements exists, forall, and choose |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| let chosen = LazyList.choose (fun x -> if x % 2 = 0 then Some x else None) ll | ||
| let first = LazyList.head chosen | ||
| Expect.equal "choose lazy first" 2 first |
Comment on lines
+537
to
+545
| test "exists returns true when element satisfies predicate" { | ||
| let ll = LazyList.ofList [ 1; 2; 3; 4; 5 ] | ||
| Expect.isTrue "exists" (LazyList.exists (fun x -> x = 3) ll) | ||
| } | ||
|
|
||
| test "exists returns false when no element satisfies predicate" { | ||
| let ll = LazyList.ofList [ 1; 2; 3; 4; 5 ] | ||
| Expect.isFalse "exists" (LazyList.exists (fun x -> x = 6) ll) | ||
| } |
29 tasks
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.
Summary
LazyListwas missing three common collection functions available inFSharp.Collections.ListandSeq:LazyList.existstrueif any element satisfies the predicate (short-circuits on first match)LazyList.foralltrueif all elements satisfy the predicate (short-circuits on first mismatch)LazyList.chooseSomevalues, skippingNoneexistsandforallare strict predicates: they traverse the list up to the first match/mismatch.choosefollows the same lazy evaluation pattern asfilter— the result list defers evaluation until consumed. This meanschooseworks correctly on infinite lazy lists (only evaluates elements up to the point consumed).Both
LazyList.fsandLazyList.fsiare updated. The public signatures use labelled parameters consistent with the rest of the.fsifile.Contributes to #152 (Align Collection Module functions with FSharp.Collections).
Test Status
✅ Build succeeded (0 errors, 31 warnings — all pre-existing)
✅
dotnet test— 766 passed, 0 failed, 6 skipped (pre-existing skips)✅ Fantomas formatting check passed
9 new tests covering:
existstrue/false/empty casesforalltrue/false/empty caseschoosekeeping Some values, all-None case, laziness verification