File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33open System
44open System.Collections .Generic
55open System.ComponentModel
6+ open FSharp.Core .CompilerServices
67open FSharpPlus
78
89// DList from FSharpx.Collections
@@ -183,6 +184,26 @@ type DList<'T> (length: int, data: DListData<'T>) =
183184 | Join ( x, y) -> yield ! walk ( y:: rights) x }
184185 ( walk [] data) .GetEnumerator ()
185186
187+ member internal this.toList () =
188+ #if FABLE_ COMPILER
189+ DList< 'T>. foldBack List.cons this []
190+ #else
191+ let mutable coll = new ListCollector<_> ()
192+ let rec walk rights = function
193+ | Nil ->
194+ match rights with
195+ | [] -> ()
196+ | t:: ts -> walk ts t
197+ | Unit x ->
198+ coll.Add x
199+ match rights with
200+ | [] -> ()
201+ | t:: ts -> walk ts t
202+ | Join ( x, y) -> walk ( y:: rights) x
203+ walk [] data
204+ coll.Close ()
205+ #endif
206+
186207 interface IEquatable< DList< 'T>> with
187208 member this.Equals ( y : DList < 'T >) =
188209 if this.Length <> y.Length then false
@@ -251,7 +272,7 @@ module DList =
251272 let ofSeq s = DList< 'T>. ofSeq s
252273
253274 /// O(n). Returns a list of the DList elements.
254- let inline toList l = foldBack List.cons l []
275+ let toList ( l : DList < 'T >) = l.toList ()
255276
256277 /// O(n). Returns a seq of the DList elements.
257278 let inline toSeq ( l : DList < 'T >) = l :> seq< 'T>
You can’t perform that action at this time.
0 commit comments