Skip to content

Commit 37bf287

Browse files
committed
+ IEquatable for DList
1 parent f0e28af commit 37bf287

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/FSharpPlus/Data/DList.fs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace FSharpPlus.Data
22

3+
open System
34
open System.Collections.Generic
45
open System.ComponentModel
56
open FSharpPlus
@@ -40,21 +41,9 @@ type DList<'T> (length: int, data: DListData<'T>) =
4041
| Some hash -> hash
4142

4243
override this.Equals other =
43-
#if FABLE_COMPILER
44-
let y = other :?> DList<'T>
45-
if this.Length <> y.Length then false
46-
else
47-
if hash this <> hash y then false
48-
else Seq.forall2 Unchecked.equals this y
49-
#else
5044
match other with
51-
| :? DList<'T> as y ->
52-
if this.Length <> y.Length then false
53-
else
54-
if this.GetHashCode () <> y.GetHashCode () then false
55-
else Seq.forall2 Unchecked.equals this y
45+
| :? DList<'T> as y -> (this :> IEquatable<DList<'T>>).Equals y
5646
| _ -> false
57-
#endif
5847

5948
/// O(1). Returns the count of elememts.
6049
member _.Length = length
@@ -175,7 +164,7 @@ type DList<'T> (length: int, data: DListData<'T>) =
175164
member s.Item
176165
with get (index: int) =
177166
let withIndex i _ = (i = index)
178-
if index < 0 || index >= s.Length then raise (System.IndexOutOfRangeException ())
167+
if index < 0 || index >= s.Length then raise (IndexOutOfRangeException ())
179168
DList.findi withIndex s
180169

181170
member _.toSeq () =
@@ -194,6 +183,12 @@ type DList<'T> (length: int, data: DListData<'T>) =
194183
| Join (x, y) -> yield! walk (y::rights) x }
195184
(walk [] data).GetEnumerator ()
196185

186+
interface IEquatable<DList<'T>> with
187+
member this.Equals(y: DList<'T>) =
188+
if this.Length <> y.Length then false
189+
elif this.GetHashCode () <> y.GetHashCode () then false
190+
else Seq.forall2 Unchecked.equals this y
191+
197192
interface IReadOnlyList<'T> with
198193
member s.Item with get index = s.Item index
199194
member s.Count = s.Length

0 commit comments

Comments
 (0)