Skip to content

Commit a704389

Browse files
make equal arguments implicit
1 parent ac7db87 commit a704389

File tree

8 files changed

+28
-28
lines changed

8 files changed

+28
-28
lines changed

src/Array.mo

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ module {
223223
///
224224
/// Space: O(size)
225225
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
226-
public func sort<T>(array : [T], compare : (T, T) -> Order.Order) : [T] {
226+
public func sort<T>(array : [T], compare : (implicit : (T, T) -> Order.Order)) : [T] {
227227
let varArray : [var T] = toVarArray(array);
228228
VarArray.sortInPlace(varArray, compare);
229229
fromVarArray(varArray)
@@ -802,7 +802,7 @@ module {
802802
/// Runtime: O(array.size())
803803
///
804804
/// Space: O(1)
805-
public func indexOf<T>(array : [T], equal : (T, T) -> Bool, element : T) : ?Nat = nextIndexOf<T>(array, equal, element, 0);
805+
public func indexOf<T>(array : [T], equal : (implicit : (T, T) -> Bool), element : T) : ?Nat = nextIndexOf<T>(array, equal, element, 0);
806806

807807
/// Returns the index of the next occurence of `element` in the `array` starting from the `from` index (inclusive).
808808
///
@@ -819,7 +819,7 @@ module {
819819
/// Runtime: O(array.size())
820820
///
821821
/// Space: O(1)
822-
public func nextIndexOf<T>(array : [T], equal : (T, T) -> Bool, element : T, fromInclusive : Nat) : ?Nat {
822+
public func nextIndexOf<T>(array : [T], equal : (implicit : (T, T) -> Bool), element : T, fromInclusive : Nat) : ?Nat {
823823
var index = fromInclusive;
824824
let size = array.size();
825825
while (index < size) {
@@ -846,7 +846,7 @@ module {
846846
/// Runtime: O(array.size())
847847
///
848848
/// Space: O(1)
849-
public func lastIndexOf<T>(array : [T], equal : (T, T) -> Bool, element : T) : ?Nat = prevIndexOf<T>(array, equal, element, array.size());
849+
public func lastIndexOf<T>(array : [T], equal : (implicit : (T, T) -> Bool), element : T) : ?Nat = prevIndexOf<T>(array, equal, element, array.size());
850850

851851
/// Returns the index of the previous occurence of `element` in the `array` starting from the `from` index (exclusive).
852852
///
@@ -866,7 +866,7 @@ module {
866866
///
867867
/// Runtime: O(array.size());
868868
/// Space: O(1);
869-
public func prevIndexOf<T>(array : [T], equal : (T, T) -> Bool, element : T, fromExclusive : Nat) : ?Nat {
869+
public func prevIndexOf<T>(array : [T], equal : (implicit : (T, T) -> Bool), element : T, fromExclusive : Nat) : ?Nat {
870870
var i = fromExclusive;
871871
while (i > 0) {
872872
i -= 1;
@@ -1076,7 +1076,7 @@ module {
10761076
/// Space: O(1)
10771077
///
10781078
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
1079-
public func compare<T>(array1 : [T], array2 : [T], compare : (T, T) -> Order.Order) : Order.Order {
1079+
public func compare<T>(array1 : [T], array2 : [T], compare : (implicit : (T, T) -> Order.Order)) : Order.Order {
10801080
let size1 = array1.size();
10811081
let size2 = array2.size();
10821082
var i = 0;
@@ -1114,7 +1114,7 @@ module {
11141114
/// Space: O(1)
11151115
///
11161116
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
1117-
public func binarySearch<T>(array : [T], compare : (T, T) -> Order.Order, element : T) : {
1117+
public func binarySearch<T>(array : [T], compare : (implicit : (T, T) -> Order.Order), element : T) : {
11181118
#found : Nat;
11191119
#insertionIndex : Nat
11201120
} {

src/Iter.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ module {
532532
/// let iter = [1, 2, 3, 4].values();
533533
/// assert Iter.contains<Nat>(iter, Nat.equal, 2);
534534
/// ```
535-
public func contains<T>(iter : Iter<T>, equal : (T, T) -> Bool, value : T) : Bool {
535+
public func contains<T>(iter : Iter<T>, equal : (implicit : (T, T) -> Bool), value : T) : Bool {
536536
for (x in iter) {
537537
if (equal(x, value)) return true
538538
};

src/List.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ module {
625625
/// Runtime: `O(size)`
626626
///
627627
/// *Runtime and space assumes that `equal` runs in `O(1)` time and space.
628-
public func indexOf<T>(list : List<T>, equal : (T, T) -> Bool, element : T) : ?Nat {
628+
public func indexOf<T>(list : List<T>, equal : (implicit : (T, T) -> Bool), element : T) : ?Nat {
629629
// inlining would save 10 instructions per entry
630630
findIndex<T>(list, func(x) = equal(element, x))
631631
};
@@ -646,7 +646,7 @@ module {
646646
/// Runtime: `O(size)`
647647
///
648648
/// *Runtime and space assumes that `equal` runs in `O(1)` time and space.
649-
public func lastIndexOf<T>(list : List<T>, equal : (T, T) -> Bool, element : T) : ?Nat {
649+
public func lastIndexOf<T>(list : List<T>, equal : (implicit : (T, T) -> Bool), element : T) : ?Nat {
650650
// inlining would save 10 instructions per entry
651651
findLastIndex<T>(list, func(x) = equal(element, x))
652652
};
@@ -1548,7 +1548,7 @@ module {
15481548
/// Space: `O(1)`
15491549
///
15501550
/// *Runtime and space assumes that `equal` runs in O(1) time and space.
1551-
public func contains<T>(list : List<T>, equal : (T, T) -> Bool, element : T) : Bool {
1551+
public func contains<T>(list : List<T>, equal : (implicit : (T, T) -> Bool), element : T) : Bool {
15521552
Option.isSome(indexOf(list, equal, element))
15531553
};
15541554

@@ -1643,7 +1643,7 @@ module {
16431643
/// Space: `O(1)`
16441644
///
16451645
/// *Runtime and space assumes that `equal` runs in O(1) time and space.
1646-
public func equal<T>(list1 : List<T>, list2 : List<T>, equal : (T, T) -> Bool) : Bool {
1646+
public func equal<T>(list1 : List<T>, list2 : List<T>, equal : (implicit : (T, T) -> Bool)) : Bool {
16471647
let size1 = size(list1);
16481648

16491649
if (size1 != size(list2)) return false;

src/Queue.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ module {
233233
/// Runtime: O(n)
234234
/// Space: O(1)
235235
/// `n` denotes the number of elements stored in the queue.
236-
public func contains<T>(queue : Queue<T>, equal : (T, T) -> Bool, element : T) : Bool {
236+
public func contains<T>(queue : Queue<T>, equal : (implicit : (T, T) -> Bool), element : T) : Bool {
237237
for (existing in values(queue)) {
238238
if (equal(existing, element)) {
239239
return true
@@ -697,7 +697,7 @@ module {
697697
/// Runtime: O(n)
698698
/// Space: O(1)
699699
/// `n` denotes the number of elements stored in the queue.
700-
public func equal<T>(queue1 : Queue<T>, queue2 : Queue<T>, equal : (T, T) -> Bool) : Bool {
700+
public func equal<T>(queue1 : Queue<T>, queue2 : Queue<T>, equal : (implicit : (T, T) -> Bool)) : Bool {
701701
if (size(queue1) != size(queue2)) {
702702
return false
703703
};

src/Stack.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ module {
270270
/// Space: O(1)
271271
/// where `n` denotes the number of elements stored on the stack and assuming
272272
/// that `equal` has O(1) costs.
273-
public func contains<T>(stack : Stack<T>, equal : (T, T) -> Bool, element : T) : Bool {
273+
public func contains<T>(stack : Stack<T>, equal : (implicit : (T, T) -> Bool), element : T) : Bool {
274274
for (existing in values(stack)) {
275275
if (equal(existing, element)) {
276276
return true
@@ -674,7 +674,7 @@ module {
674674
/// Space: O(1)
675675
/// where `n` denotes the number of elements stored on the stack and
676676
/// assuming that `equal` has O(1) costs.
677-
public func equal<T>(stack1 : Stack<T>, stack2 : Stack<T>, equal : (T, T) -> Bool) : Bool {
677+
public func equal<T>(stack1 : Stack<T>, stack2 : Stack<T>, equal : (implicit : (T, T) -> Bool)) : Bool {
678678
if (size(stack1) != size(stack2)) {
679679
return false
680680
};

src/VarArray.mo

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module {
9999
/// Space: O(1)
100100
///
101101
/// *Runtime and space assumes that `equal` runs in O(1) time and space.
102-
public func equal<T>(array1 : [var T], array2 : [var T], equal : (T, T) -> Bool) : Bool {
102+
public func equal<T>(array1 : [var T], array2 : [var T], equal : (implicit : (T, T) -> Bool)) : Bool {
103103
let size1 = array1.size();
104104
let size2 = array2.size();
105105
if (size1 != size2) {
@@ -202,7 +202,7 @@ module {
202202
///
203203
/// Space: O(size)
204204
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
205-
public func sort<T>(array : [var T], compare : (T, T) -> Order.Order) : [var T] {
205+
public func sort<T>(array : [var T], compare : (implicit : (T, T) -> Order.Order)) : [var T] {
206206
let newArray = clone(array);
207207
sortInPlace(newArray, compare);
208208
newArray
@@ -222,7 +222,7 @@ module {
222222
///
223223
/// Space: O(size)
224224
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
225-
public func sortInPlace<T>(array : [var T], compare : (T, T) -> Order.Order) : () {
225+
public func sortInPlace<T>(array : [var T], compare : (implicit : (T, T) -> Order.Order)) : () {
226226
// Stable merge sort in a bottom-up iterative style. Same algorithm as the sort in Buffer.
227227
let size = array.size();
228228
if (size == 0) {
@@ -945,7 +945,7 @@ module {
945945
/// Runtime: O(array.size())
946946
///
947947
/// Space: O(1)
948-
public func indexOf<T>(array : [var T], equal : (T, T) -> Bool, element : T) : ?Nat = nextIndexOf<T>(array, equal, element, 0);
948+
public func indexOf<T>(array : [var T], equal : (implicit : (T, T) -> Bool), element : T) : ?Nat = nextIndexOf<T>(array, equal, element, 0);
949949

950950
/// Returns the index of the next occurence of `element` in the `array` starting from the `from` index (inclusive).
951951
///
@@ -963,7 +963,7 @@ module {
963963
/// Runtime: O(array.size())
964964
///
965965
/// Space: O(1)
966-
public func nextIndexOf<T>(array : [var T], equal : (T, T) -> Bool, element : T, fromInclusive : Nat) : ?Nat {
966+
public func nextIndexOf<T>(array : [var T], equal : (implicit : (T, T) -> Bool), element : T, fromInclusive : Nat) : ?Nat {
967967
var index = fromInclusive;
968968
let size = array.size();
969969
while (index < size) {
@@ -991,7 +991,7 @@ module {
991991
/// Runtime: O(array.size())
992992
///
993993
/// Space: O(1)
994-
public func lastIndexOf<T>(array : [var T], equal : (T, T) -> Bool, element : T) : ?Nat = prevIndexOf<T>(array, equal, element, array.size());
994+
public func lastIndexOf<T>(array : [var T], equal : (implicit : (T, T) -> Bool), element : T) : ?Nat = prevIndexOf<T>(array, equal, element, array.size());
995995

996996
/// Returns the index of the previous occurence of `element` in the `array` starting from the `from` index (exclusive).
997997
///
@@ -1006,7 +1006,7 @@ module {
10061006
///
10071007
/// Runtime: O(array.size());
10081008
/// Space: O(1);
1009-
public func prevIndexOf<T>(array : [var T], equal : (T, T) -> Bool, element : T, fromExclusive : Nat) : ?Nat {
1009+
public func prevIndexOf<T>(array : [var T], equal : (implicit : (T, T) -> Bool), element : T, fromExclusive : Nat) : ?Nat {
10101010
var i = fromExclusive;
10111011
while (i > 0) {
10121012
i -= 1;
@@ -1209,7 +1209,7 @@ module {
12091209
/// Space: O(1)
12101210
///
12111211
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
1212-
public func compare<T>(array1 : [var T], array2 : [var T], compare : (T, T) -> Order.Order) : Order.Order {
1212+
public func compare<T>(array1 : [var T], array2 : [var T], compare : (implicit : (T, T) -> Order.Order)) : Order.Order {
12131213
let size1 = array1.size();
12141214
let size2 = array2.size();
12151215
var i = 0;
@@ -1245,7 +1245,7 @@ module {
12451245
/// Space: O(1)
12461246
///
12471247
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
1248-
public func binarySearch<T>(array : [var T], compare : (T, T) -> Order.Order, element : T) : {
1248+
public func binarySearch<T>(array : [var T], compare : (implicit : (T, T) -> Order.Order), element : T) : {
12491249
#found : Nat;
12501250
#insertionIndex : Nat
12511251
} {

src/pure/List.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module {
9999
/// Space: O(1)
100100
///
101101
/// *Runtime and space assumes that `equal` runs in O(1) time and space.
102-
public func contains<T>(list : List<T>, equal : (T, T) -> Bool, item : T) : Bool = switch list {
102+
public func contains<T>(list : List<T>, equal : (implicit : (T, T) -> Bool), item : T) : Bool = switch list {
103103
case (?(h, t)) equal(h, item) or contains(t, equal, item);
104104
case _ false
105105
};

src/pure/Queue.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module {
125125
/// Runtime: `O(size)`
126126
///
127127
/// Space: `O(1)`
128-
public func contains<T>(queue : Queue<T>, equal : (T, T) -> Bool, item : T) : Bool = List.contains(queue.0, equal, item) or List.contains(queue.2, equal, item);
128+
public func contains<T>(queue : Queue<T>, equal : (implicit : (T, T) -> Bool), item : T) : Bool = List.contains(queue.0, equal, item) or List.contains(queue.2, equal, item);
129129

130130
/// Inspect the optional element on the front end of a queue.
131131
/// Returns `null` if `queue` is empty. Otherwise, the front element of `queue`.
@@ -401,7 +401,7 @@ module {
401401
/// Runtime: O(size)
402402
///
403403
/// Space: O(size)
404-
public func equal<T>(queue1 : Queue<T>, queue2 : Queue<T>, equal : (T, T) -> Bool) : Bool {
404+
public func equal<T>(queue1 : Queue<T>, queue2 : Queue<T>, equal : (implicit : (T, T) -> Bool)) : Bool {
405405
if (queue1.1 != queue2.1) {
406406
return false
407407
};

0 commit comments

Comments
 (0)