[Repo Assist] feat: add map, filter, iter, exists, forall, toList, toArray to Queue and Deque#241
Open
github-actions[bot] wants to merge 2 commits intomasterfrom
Conversation
… and Deque modules Adds commonly needed collection functions to Queue and Deque that were present in F# List but missing from these modules. Addresses part of #152 (Align Collection Module functions with FSharp.Collections). New functions for both Queue and Deque: - map : transform each element, returning the same collection type - filter : keep elements matching a predicate - iter : apply a side-effecting function to each element (FIFO order) - exists : test whether any element satisfies a predicate - forall : test whether all elements satisfy a predicate - toList : convert to list in FIFO order - toArray : convert to array in FIFO order All seven functions are O(n) and preserve FIFO element order. 21 new tests added (QueueTest and DequeTest), all passing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 10, 2026
github-actions bot
added a commit
that referenced
this pull request
Mar 13, 2026
… tests Adds six new module-level functions to DList, mirroring the functions added to Queue and Deque in #241, and further addressing #152. - DList.map: transforms all elements using a function - DList.filter: retains elements matching a predicate - DList.iter: applies an action to each element in order - DList.exists: short-circuit check if any element matches - DList.forall: short-circuit check if all elements match - DList.toArray: returns elements as an array map and filter are implemented via foldBack so they build a DList directly (preserving the length invariant). iter/exists/forall/toArray delegate to the IEnumerable<'T> implementation for correct short-circuit behaviour. Also adds 21 new tests: 14 unit tests and 7 property-based tests that verify results match standard List/Array equivalents. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds FSharp.Collections-aligned collection helpers to Queue and Deque, expanding their module APIs with common traversal/transformation/conversion functions while preserving the collections’ logical ordering.
Changes:
- Added
toList,toArray,map,filter,iter,exists,foralltoQueueandDequeimplementations. - Exposed the new functions in the corresponding
.fsisignature files. - Added unit tests covering the new APIs (order preservation and basic semantics).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/FSharpx.Collections/Queue.fs |
Implements the seven new Queue module functions. |
src/FSharpx.Collections/Queue.fsi |
Adds public signatures/docs for the new Queue functions (also includes spacing/formatting changes). |
src/FSharpx.Collections/Deque.fs |
Implements the seven new Deque module functions. |
src/FSharpx.Collections/Deque.fsi |
Adds public signatures/docs for the new Deque functions (also includes spacing/formatting changes). |
tests/FSharpx.Collections.Tests/QueueTest.fs |
Adds tests for new Queue APIs (FIFO order and basic behavior). |
tests/FSharpx.Collections.Tests/DequeTest.fs |
Adds tests for new Deque APIs (order and basic behavior). |
💡 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.
|
|
||
| ///O(n). Returns true if any element of the queue satisfies the given predicate. | ||
| let exists (predicate: 'T -> bool) (q: Queue<'T>) : bool = | ||
| List.exists predicate q.front || List.exists predicate q.rBack |
|
|
||
| ///O(n). Returns true if all elements of the queue satisfy the given predicate. | ||
| let forall (predicate: 'T -> bool) (q: Queue<'T>) : bool = | ||
| List.forall predicate q.front && List.forall predicate q.rBack |
Comment on lines
+270
to
+274
| List.exists predicate q.front || List.exists predicate q.rBack | ||
|
|
||
| ///O(n). Returns true if all elements of the deque satisfy the given predicate. | ||
| let forall (predicate: 'T -> bool) (q: Deque<'T>) : bool = | ||
| List.forall predicate q.front && List.forall predicate q.rBack |
Comment on lines
+270
to
+274
| List.exists predicate q.front || List.exists predicate q.rBack | ||
|
|
||
| ///O(n). Returns true if all elements of the deque satisfy the given predicate. | ||
| let forall (predicate: 'T -> bool) (q: Deque<'T>) : bool = | ||
| List.forall predicate q.front && List.forall predicate q.rBack |
Comment on lines
+49
to
53
| val (|Cons|Nil|): Queue<'T> -> Choice<('T * Queue<'T>), unit> | ||
|
|
||
| ///O(1). Returns a new queue with the element added to the end. (enqueue) | ||
| val inline conj : 'T -> Queue<'T> -> Queue<'T> | ||
| val inline conj: 'T -> Queue<'T> -> Queue<'T> | ||
|
|
Comment on lines
+69
to
88
| val (|Cons|Nil|): Deque<'T> -> Choice<('T * Deque<'T>), unit> | ||
|
|
||
| val (|Conj|Nil|) : Deque<'T> -> Choice<(Deque<'T> * 'T),unit> | ||
| val (|Conj|Nil|): Deque<'T> -> Choice<(Deque<'T> * 'T), unit> | ||
|
|
||
| ///O(1). Returns a new deque with the element added to the end. | ||
| val inline conj : 'T -> Deque<'T> -> Deque<'T> | ||
| val inline conj: 'T -> Deque<'T> -> Deque<'T> | ||
|
|
||
| ///O(1). Returns a new deque with the element added to the beginning. | ||
| val inline cons : 'T -> Deque<'T> -> Deque<'T> | ||
| val inline cons: 'T -> Deque<'T> -> Deque<'T> | ||
|
|
||
| ///O(1). Returns deque of no elements. | ||
| [<GeneralizableValue>] | ||
| val empty<'T> : Deque<'T> | ||
|
|
||
| ///O(n). Applies a function to each element of the deque, threading an accumulator argument through the computation, left to right | ||
| val fold : ('State -> 'T -> 'State) -> 'State -> Deque<'T> -> 'State | ||
| val fold: ('State -> 'T -> 'State) -> 'State -> Deque<'T> -> 'State | ||
|
|
||
| ///O(n). Applies a function to each element of the deque, threading an accumulator argument through the computation, right to left | ||
| val foldBack : ('T -> 'State -> 'State) -> Deque<'T> -> 'State -> 'State | ||
| val foldBack: ('T -> 'State -> 'State) -> Deque<'T> -> 'State -> 'State | ||
|
|
| let q = Deque.ofSeq [ 1; 2; 3; 4; 5 ] | ||
| Expect.equal "filter order" [ 1; 3; 5 ] (Deque.filter (fun x -> x % 2 <> 0) q |> Deque.toList) | ||
| } | ||
|
|
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.
Adds seven commonly used collection functions to the
QueueandDequemodules. Partially addresses #152 (Align Collection Module functions with FSharp.Collections).Changes
New functions (Queue and Deque)
map f qQueue/Dequefilter pred qiter f qexists pred qforall pred qtoList qtoArray qAll functions preserve FIFO element order. Signatures added to
.fsifiles. 21 new tests added.Implementation notes
Queue.mapdirectly maps over the internalfrontandrBacklists, preserving the queue structure without any rebuilding — very efficient.Queue.filterhandles the invariant thatfrontshould not be empty for a non-empty queue: if filtering removes allfrontelements,List.rev rBackbecomes the newfront.Deque.mapsimilarly maps directly over both internal lists.Deque.filteris simpler since Deque tolerates an emptyfront(it falls back torBack).existsandforallcan checkrBackin any order (order only matters foriter,toList,toArray).Test Status
All 731 tests pass (6 pre-existing
ptestskips unrelated to this PR):