@@ -184,26 +184,6 @@ type DList<'T> (length: int, data: DListData<'T>) =
184184 | Join ( x, y) -> yield ! walk ( y:: rights) x }
185185 ( walk [] data) .GetEnumerator ()
186186
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-
207187 interface IEquatable< DList< 'T>> with
208188 member this.Equals ( y : DList < 'T >) =
209189 if this.Length <> y.Length then false
@@ -271,8 +251,30 @@ module DList =
271251 /// O(n). Returns a DList of the seq.
272252 let ofSeq s = DList< 'T>. ofSeq s
273253
274- /// O(n). Returns a list of the DList elements.
275- let toList ( l : DList < 'T >) = l.toList ()
254+ /// Iterates over each element of the list.
255+ let iter action ( source : DList < 'T >) =
256+ let rec walk rights = function
257+ | Nil ->
258+ match rights with
259+ | [] -> ()
260+ | t:: ts -> walk ts t
261+ | Unit x ->
262+ action x
263+ match rights with
264+ | [] -> ()
265+ | t:: ts -> walk ts t
266+ | Join ( x, y) -> walk ( y:: rights) x
267+ walk [] source.dc
268+
269+ /// Returns a list of the DList elements.
270+ let toList ( source : DList < 'T >) =
271+ #if FABLE_ COMPILER
272+ DList< 'T>. foldBack List.cons source []
273+ #else
274+ let mutable coll = new ListCollector<_> ()
275+ iter ( fun x -> coll.Add x) source
276+ coll.Close ()
277+ #endif
276278
277279 /// O(n). Returns a seq of the DList elements.
278280 let inline toSeq ( l : DList < 'T >) = l :> seq< 'T>
0 commit comments