Skip to content

Commit

Permalink
Use ListCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty authored Jan 15, 2024
1 parent b9a5c98 commit 00c4867
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/FSharpPlus/Data/DList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ type DList<'T> (length: int, data: DListData<'T>) =
| Join (x, y) -> yield! walk (y::rights) x }
(walk [] data).GetEnumerator ()

member internal this.toList () =
#if FABLE_COMPILER
DList<'T>.foldBack List.cons this []
#else

Check failure on line 189 in src/FSharpPlus/Data/DList.fs

View workflow job for this annotation

GitHub Actions / testFable3SubsetOnCore

End of file in #if section begun at or after here
let mutable coll = new ListCollector<_> ()
let rec walk rights = function
| Nil ->
match rights with
| [] -> ()
| t::ts -> walk ts t
| Unit x ->
coll.Add x
match rights with
| [] -> ()
| t::ts -> walk ts t
| Join (x, y) -> walk (y::rights) x
walk [] data
coll.Close ()

interface IEquatable<DList<'T>> with
member this.Equals(y: DList<'T>) =
if this.Length <> y.Length then false
Expand Down Expand Up @@ -251,7 +270,7 @@ module DList =
let ofSeq s = DList<'T>.ofSeq s

/// O(n). Returns a list of the DList elements.
let inline toList l = foldBack List.cons l []
let toList (l: DList<'T>) = l.toList ()

/// O(n). Returns a seq of the DList elements.
let inline toSeq (l: DList<'T>) = l :> seq<'T>
Expand Down

0 comments on commit 00c4867

Please sign in to comment.