Skip to content

Commit 8d5e501

Browse files
committed
Use Self for std.cmp.Equal and std.cmp.Compare
Similar to std.clone.Clone, this makes implementing these traits less awkward and better captures their intent (= comparisons against values of the same type). Changelog: changed
1 parent 780a912 commit 8d5e501

34 files changed

+106
-127
lines changed

std/src/std/array.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ impl Drop for Array {
730730
}
731731
}
732732

733-
impl Contains[T] for Array if T: Equal[ref T] {
733+
impl Contains[T] for Array if T: Equal {
734734
# Returns `true` if `self` contains the given value.
735735
#
736736
# # Examples
@@ -757,7 +757,7 @@ impl Clone for Array if T: Clone {
757757
}
758758
}
759759

760-
impl Equal[ref Array[T]] for Array if T: Equal[ref T] {
760+
impl Equal for Array if T: Equal {
761761
# Returns `true` if `self` and the given `Array` are identical.
762762
#
763763
# # Examples

std/src/std/base64.inko

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl Format for DecodeError {
741741
}
742742
}
743743

744-
impl Equal[ref DecodeError] for DecodeError {
744+
impl Equal for DecodeError {
745745
fn pub ==(other: ref DecodeError) -> Bool {
746746
match (self, other) {
747747
case (InvalidSize, InvalidSize) -> true

std/src/std/bool.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ impl Clone for Bool {
6464
}
6565
}
6666

67-
impl Equal[ref Bool] for Bool {
67+
impl Equal for Bool {
6868
fn pub inline ==(other: ref Bool) -> Bool {
6969
_INKO.bool_eq(self, other)
7070
}
7171
}
7272

73-
impl Compare[Bool] for Bool {
73+
impl Compare for Bool {
7474
fn pub inline cmp(other: ref Bool) -> Ordering {
7575
to_int.cmp(other.to_int)
7676
}

std/src/std/byte_array.inko

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl IntoString for ByteArray {
690690
}
691691
}
692692

693-
impl Equal[ref ByteArray] for ByteArray {
693+
impl Equal for ByteArray {
694694
# Returns `true` if two `ByteArray` objects are equal to each other.
695695
#
696696
# Two `ByteArray` objects are considered equal if they have the exact same

std/src/std/cmp.inko

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type pub copy enum Ordering {
99
case Greater
1010
}
1111

12-
impl Equal[ref Ordering] for Ordering {
12+
impl Equal for Ordering {
1313
fn pub inline ==(other: ref Ordering) -> Bool {
1414
match (self, other) {
1515
case (Less, Less) -> true
@@ -33,42 +33,42 @@ impl Format for Ordering {
3333
}
3434

3535
# A type that can be compared to another type for a sort-order.
36-
trait pub Compare[T] {
36+
trait pub Compare {
3737
# Returns the ordering between `self` and the given argument.
3838
#
3939
# The returned value should be as follows:
4040
#
4141
# - `a == b`: `Ordering.Equal`
4242
# - `a > b`: `Ordering.Greater`
4343
# - `a < b`: `Ordering.Less`
44-
fn pub cmp(other: ref T) -> Ordering
44+
fn pub cmp(other: ref Self) -> Ordering
4545

4646
# Returns `true` if `self` is lower than the given argument.
47-
fn pub <(other: ref T) -> Bool {
47+
fn pub <(other: ref Self) -> Bool {
4848
match cmp(other) {
4949
case Less -> true
5050
case _ -> false
5151
}
5252
}
5353

5454
# Returns `true` if `self` is lower than or equal to the given argument.
55-
fn pub <=(other: ref T) -> Bool {
55+
fn pub <=(other: ref Self) -> Bool {
5656
match cmp(other) {
5757
case Less or Equal -> true
5858
case _ -> false
5959
}
6060
}
6161

6262
# Returns `true` if `self` is greater than the given argument.
63-
fn pub >(other: ref T) -> Bool {
63+
fn pub >(other: ref Self) -> Bool {
6464
match cmp(other) {
6565
case Greater -> true
6666
case _ -> false
6767
}
6868
}
6969

7070
# Returns `true` if `self` is equal to or greater than the given argument.
71-
fn pub >=(other: ref T) -> Bool {
71+
fn pub >=(other: ref Self) -> Bool {
7272
match cmp(other) {
7373
case Greater or Equal -> true
7474
case _ -> false
@@ -77,18 +77,18 @@ trait pub Compare[T] {
7777
}
7878

7979
# A type that can be compared for equality.
80-
trait pub Equal[T] {
80+
trait pub Equal {
8181
# Returns `true` if `self` and the given object are equal to each other.
8282
#
8383
# This operator is used to perform structural equality. This means two objects
8484
# residing in different memory locations may be considered equal, provided
8585
# their structure is equal. For example, two different arrays may be
8686
# considered to have structural equality if they contain the exact same
8787
# values.
88-
fn pub ==(other: T) -> Bool
88+
fn pub ==(other: ref Self) -> Bool
8989

9090
# Returns `true` if `self` and the given object are not equal to each other.
91-
fn pub !=(other: T) -> Bool {
91+
fn pub !=(other: ref Self) -> Bool {
9292
(self == other).false?
9393
}
9494
}
@@ -108,7 +108,7 @@ trait pub Contains[T] {
108108
#
109109
# min(10, 5) # => 5
110110
# ```
111-
fn pub inline min[T: Compare[T]](a: T, b: T) -> T {
111+
fn pub inline min[T: Compare](a: T, b: T) -> T {
112112
if a <= b { a } else { b }
113113
}
114114

@@ -121,6 +121,6 @@ fn pub inline min[T: Compare[T]](a: T, b: T) -> T {
121121
#
122122
# max(10, 5) # => 10
123123
# ```
124-
fn pub inline max[T: Compare[T]](a: T, b: T) -> T {
124+
fn pub inline max[T: Compare](a: T, b: T) -> T {
125125
if a >= b { a } else { b }
126126
}

std/src/std/crypto/hash.inko

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl ToString for Hash {
145145
}
146146
}
147147

148-
impl Equal[ref Hash] for Hash {
148+
impl Equal for Hash {
149149
fn pub ==(other: ref Hash) -> Bool {
150150
@bytes == other.bytes
151151
}

std/src/std/crypto/pem.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Format for Item {
9393
}
9494
}
9595

96-
impl Equal[ref Item] for Item {
96+
impl Equal for Item {
9797
fn pub ==(other: ref Item) -> Bool {
9898
match (self, other) {
9999
case (Certificate(a), Certificate(b)) -> a == b
@@ -135,7 +135,7 @@ impl Format for ParseError {
135135
}
136136
}
137137

138-
impl Equal[ref ParseError] for ParseError {
138+
impl Equal for ParseError {
139139
fn pub ==(other: ref ParseError) -> Bool {
140140
match (self, other) {
141141
case (Read(a), Read(b)) -> a == b

std/src/std/crypto/x509.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Format for Certificate {
2020
}
2121
}
2222

23-
impl Equal[ref Certificate] for Certificate {
23+
impl Equal for Certificate {
2424
fn pub ==(other: ref Certificate) -> Bool {
2525
@bytes == other.bytes
2626
}
@@ -44,7 +44,7 @@ impl Format for PrivateKey {
4444
}
4545
}
4646

47-
impl Equal[ref PrivateKey] for PrivateKey {
47+
impl Equal for PrivateKey {
4848
fn pub ==(other: ref PrivateKey) -> Bool {
4949
@bytes == other.bytes
5050
}

std/src/std/csv.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Format for Error {
9494
}
9595
}
9696

97-
impl Equal[ref Error] for Error {
97+
impl Equal for Error {
9898
fn pub ==(other: ref Error) -> Bool {
9999
@kind == other.kind and @offset == other.offset
100100
}
@@ -128,7 +128,7 @@ impl Format for ErrorKind {
128128
}
129129
}
130130

131-
impl Equal[ref ErrorKind] for ErrorKind {
131+
impl Equal for ErrorKind {
132132
fn pub ==(other: ref ErrorKind) -> Bool {
133133
match (self, other) {
134134
case (Read(a), Read(b)) -> a == b

std/src/std/float.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl Power[Int, Float] for Float {
318318
}
319319
}
320320

321-
impl Compare[Float] for Float {
321+
impl Compare for Float {
322322
# Return the ordering between `self` and `other`.
323323
#
324324
# This method implements total ordering of floats as per the IEEE 754
@@ -363,7 +363,7 @@ impl Compare[Float] for Float {
363363
}
364364
}
365365

366-
impl Equal[ref Float] for Float {
366+
impl Equal for Float {
367367
# Returns `true` if `self` and `other` are equal to each other.
368368
#
369369
# This method uses "Units in the Last Place" or ULPs to perform an approximate

std/src/std/fs.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type pub copy enum FileType {
4343
}
4444
}
4545

46-
impl Equal[ref FileType] for FileType {
46+
impl Equal for FileType {
4747
fn pub ==(other: ref FileType) -> Bool {
4848
match (self, other) {
4949
case (File, File) -> true
@@ -80,7 +80,7 @@ type pub inline DirectoryEntry {
8080
let pub @type: FileType
8181
}
8282

83-
impl Equal[ref DirectoryEntry] for DirectoryEntry {
83+
impl Equal for DirectoryEntry {
8484
fn pub ==(other: ref DirectoryEntry) -> Bool {
8585
@path == other.path and @type == other.type
8686
}

std/src/std/fs/path.inko

+1-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ type pub inline Path {
885885
}
886886
}
887887

888-
impl Equal[ref Path] for Path {
888+
impl Equal for Path {
889889
# Returns `true` if `self` is equal to the given `Path`.
890890
#
891891
# # Examples

std/src/std/int.inko

+2-2
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ impl ToFloat for Int {
648648
}
649649
}
650650

651-
impl Compare[Int] for Int {
651+
impl Compare for Int {
652652
fn pub inline cmp(other: ref Int) -> Ordering {
653653
if self > other {
654654
Ordering.Greater
@@ -676,7 +676,7 @@ impl Compare[Int] for Int {
676676
}
677677
}
678678

679-
impl Equal[ref Int] for Int {
679+
impl Equal for Int {
680680
fn pub inline ==(other: ref Int) -> Bool {
681681
_INKO.int_eq(self, other)
682682
}

std/src/std/io.inko

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl Format for Error {
374374
}
375375
}
376376

377-
impl Equal[ref Error] for Error {
377+
impl Equal for Error {
378378
fn pub ==(other: ref Error) -> Bool {
379379
match (self, other) {
380380
case (AddressInUse, AddressInUse) -> true

std/src/std/json.inko

+5-5
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ type pub inline enum ErrorKind {
160160
case Read(IoError)
161161
}
162162

163-
impl Equal[ref ErrorKind] for ErrorKind {
163+
impl Equal for ErrorKind {
164164
fn pub ==(other: ref ErrorKind) -> Bool {
165165
match (self, other) {
166166
case (RecursionLimitExceeded(a), RecursionLimitExceeded(b)) -> a == b
@@ -222,7 +222,7 @@ type pub inline Error {
222222
}
223223
}
224224

225-
impl Equal[ref Error] for Error {
225+
impl Equal for Error {
226226
fn pub ==(other: ref Error) -> Bool {
227227
@kind == other.kind and @offset == other.offset
228228
}
@@ -534,7 +534,7 @@ impl FormatTrait for Json {
534534
}
535535
}
536536

537-
impl Equal[ref Json] for Json {
537+
impl Equal for Json {
538538
fn pub ==(other: ref Json) -> Bool {
539539
match (self, other) {
540540
case (Int(a), Int(b)) -> a == b
@@ -555,7 +555,7 @@ type pub copy enum Number {
555555
case Float(Float)
556556
}
557557

558-
impl Equal[ref Number] for Number {
558+
impl Equal for Number {
559559
fn pub ==(other: ref Number) -> Bool {
560560
match (self, other) {
561561
case (Int(a), Int(b)) -> a == b
@@ -585,7 +585,7 @@ type pub copy enum Type {
585585
case String
586586
}
587587

588-
impl Equal[ref Type] for Type {
588+
impl Equal for Type {
589589
fn pub ==(other: ref Type) -> Bool {
590590
match (self, other) {
591591
case (Array, Array) -> true

std/src/std/map.inko

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let EMPTY = -1
1717
let DEFAULT_CAPACITY = 4
1818

1919
# An entry stored in a Map.
20-
type pub Entry[K: Equal[ref K] + Hash, V] {
20+
type pub Entry[K: Equal + Hash, V] {
2121
# The key that was hashed.
2222
let @key: K
2323

@@ -89,7 +89,7 @@ impl Clone for Entry if K: Clone, V: Clone {
8989
# - <http://codecapsule.com/2013/11/11/robin-hood-hashing/>
9090
# - <http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/>
9191
# - <https://www.sebastiansylvan.com/post/robin-hood-hashing-should-be-your-default-hash-table-implementation/>
92-
type pub Map[K: Equal[ref K] + Hash, V] {
92+
type pub Map[K: Equal + Hash, V] {
9393
# The slots we can hash into.
9494
#
9595
# An index of `-1` indicates the slot isn't used. A value of `0` or more
@@ -647,7 +647,7 @@ impl Map if V: mut {
647647
}
648648
}
649649

650-
impl Equal[ref Map[K, V]] for Map if V: Equal[ref V] {
650+
impl Equal for Map if V: Equal {
651651
# Returns `true` if `self` and the given `Map` are identical to each
652652
# other.
653653
#

std/src/std/net/dns.inko

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Format for Error {
4646
}
4747
}
4848

49-
impl Equal[ref Error] for Error {
49+
impl Equal for Error {
5050
fn pub ==(other: ref Error) -> Bool {
5151
match (self, other) {
5252
case (InvalidHost, InvalidHost) -> true

std/src/std/net/ip.inko

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ type pub copy enum IpAddress {
168168
}
169169
}
170170

171-
impl Equal[ref IpAddress] for IpAddress {
171+
impl Equal for IpAddress {
172172
fn pub inline ==(other: ref IpAddress) -> Bool {
173173
match self {
174174
case V4(a) -> {
@@ -500,7 +500,7 @@ impl FormatTrait for Ipv6Address {
500500
}
501501
}
502502

503-
impl Equal[ref Ipv6Address] for Ipv6Address {
503+
impl Equal for Ipv6Address {
504504
# Returns `true` if `self` and the given IP address are the same.
505505
#
506506
# # Examples
@@ -891,7 +891,7 @@ impl FormatTrait for Ipv4Address {
891891
}
892892
}
893893

894-
impl Equal[ref Ipv4Address] for Ipv4Address {
894+
impl Equal for Ipv4Address {
895895
# Returns `true` if `self` and the given IP address are the same.
896896
#
897897
# # Examples

0 commit comments

Comments
 (0)