Skip to content

Commit 1b1c880

Browse files
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c2a93a4 commit 1b1c880

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/FSharpx.Collections/Deque.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ module Deque =
244244
let inline toSeq(q: Deque<'T>) =
245245
q :> seq<'T>
246246

247-
///O(n). Returns a list of the deque elements in FIFO order.
247+
///O(n). Returns a list of the deque elements in front-to-back (head-to-last) order.
248248
let toList(q: Deque<'T>) : 'T list =
249249
q.front @ List.rev q.rBack
250250

251-
///O(n). Returns an array of the deque elements in FIFO order.
251+
///O(n). Returns an array of the deque elements in front-to-back (head-to-last) order.
252252
let toArray(q: Deque<'T>) : 'T[] =
253253
Array.ofSeq q
254254

src/FSharpx.Collections/Deque.fsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ module Deque =
143143
///O(n). Views the given deque as a sequence.
144144
val inline toSeq: Deque<'T> -> seq<'T>
145145

146-
///O(n). Returns a list of the deque elements in FIFO order.
146+
///O(n). Returns a list of the deque elements in front-to-back (head-to-last) order.
147147
val toList: Deque<'T> -> 'T list
148148

149-
///O(n). Returns an array of the deque elements in FIFO order.
149+
///O(n). Returns an array of the deque elements in front-to-back (head-to-last) order.
150150
val toArray: Deque<'T> -> 'T[]
151151

152152
///O(n). Returns a new deque whose elements are the results of applying the given function to each element.
@@ -159,11 +159,11 @@ module Deque =
159159
val iter: ('T -> unit) -> Deque<'T> -> unit
160160

161161
///O(n). Returns true if any element of the deque satisfies the given predicate.
162-
///Note: elements are not necessarily checked in FIFO order; the internal rear list is checked in reverse (LIFO) order.
162+
///Note: elements are not necessarily checked in front-to-back (enumeration) order; the internal rear list is checked in reverse order.
163163
val exists: ('T -> bool) -> Deque<'T> -> bool
164164

165165
///O(n). Returns true if all elements of the deque satisfy the given predicate.
166-
///Note: elements are not necessarily checked in FIFO order; the internal rear list is checked in reverse (LIFO) order.
166+
///Note: elements are not necessarily checked in front-to-back (enumeration) order; the internal rear list is checked in reverse order.
167167
val forall: ('T -> bool) -> Deque<'T> -> bool
168168

169169
///O(1) amortized, O(n), worst case. Returns option first element and tail.

tests/FSharpx.Collections.Tests/DequeTest.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,9 @@ module DequeTests =
12231223
(Prop.forAll(Arb.fromGen intGensStart2.[2])
12241224
<| fun (q, l) -> List.ofSeq q.TryInitial.Value = (List.rev l |> List.tail |> List.rev))
12251225

1226-
test "toList preserves FIFO order" {
1226+
test "toList preserves front-to-back order" {
12271227
let q = Deque.ofSeq [ 1; 2; 3; 4; 5 ]
1228-
Expect.equal "toList" [ 1; 2; 3; 4; 5 ] (Deque.toList q)
1228+
Expect.equal "toList preserves front-to-back order" [ 1; 2; 3; 4; 5 ] (Deque.toList q)
12291229
}
12301230

12311231
test "toList empty deque" { Expect.equal "toList empty" [] (Deque.toList Deque.empty) }

tests/FSharpx.Collections.Tests/QueueTest.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ module QueueTests =
330330
Expect.equal "toArray" [| 1; 2; 3 |] (Queue.toArray q)
331331
}
332332

333+
test "toArray preserves FIFO order across front/rBack boundary" {
334+
let q = Queue.ofSeq [ 1; 2; 3 ] |> Queue.conj 4 |> Queue.conj 5
335+
Expect.equal "toArray front/rBack" [| 1; 2; 3; 4; 5 |] (Queue.toArray q)
336+
}
337+
338+
test "toArray empty queue" { Expect.equal "toArray empty" [||] (Queue.toArray Queue.empty) }
333339
test "map transforms elements" {
334340
let q = Queue.ofSeq [ 1; 2; 3 ]
335341
Expect.equal "map" [ 2; 4; 6 ] (Queue.map ((*) 2) q |> Queue.toList)

0 commit comments

Comments
 (0)