diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 00000000..27b720e3
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,4 @@
+{
+ "semi": false,
+ "trailingComma": "none"
+}
diff --git a/src/Array.mo b/src/Array.mo
index f95191f6..653418ec 100644
--- a/src/Array.mo
+++ b/src/Array.mo
@@ -61,9 +61,9 @@ module {
var i = 0;
while (i < size) {
array[i] := generator i;
- i += 1;
+ i += 1
};
- array;
+ array
};
/// Transforms a mutable array into an immutable array.
@@ -96,15 +96,15 @@ module {
public func thaw(array : [A]) : [var A] {
let size = array.size();
if (size == 0) {
- return [var];
+ return [var]
};
let newArray = Prim.Array_init(size, array[0]);
var i = 0;
while (i < size) {
newArray[i] := array[i];
- i += 1;
+ i += 1
};
- newArray;
+ newArray
};
/// Tests if two arrays contain equal values (i.e. they represent the same
@@ -128,16 +128,16 @@ module {
let size1 = array1.size();
let size2 = array2.size();
if (size1 != size2) {
- return false;
+ return false
};
var i = 0;
while (i < size1) {
if (not equal(array1[i], array2[i])) {
- return false;
+ return false
};
- i += 1;
+ i += 1
};
- return true;
+ return true
};
/// Returns the first value in `array` for which `predicate` returns true.
@@ -155,10 +155,10 @@ module {
public func find(array : [X], predicate : X -> Bool) : ?X {
for (element in array.vals()) {
if (predicate element) {
- return ?element;
- };
+ return ?element
+ }
};
- return null;
+ return null
};
/// Create a new array by appending the values of `array1` and `array2`.
@@ -180,12 +180,12 @@ module {
size1 + size2,
func i {
if (i < size1) {
- array1[i];
+ array1[i]
} else {
- array2[i - size1];
- };
- },
- );
+ array2[i - size1]
+ }
+ }
+ )
};
// FIXME this example stack overflows. Should test with new implementation of sortInPlace
@@ -205,7 +205,7 @@ module {
public func sort(array : [X], compare : (X, X) -> Order.Order) : [X] {
let temp : [var X] = thaw(array);
sortInPlace(temp, compare);
- freeze(temp);
+ freeze(temp)
};
/// Sorts the elements in the array, __in place__, according to `compare`.
@@ -227,7 +227,7 @@ module {
// Stable merge sort in a bottom-up iterative style. Same algorithm as the sort in Buffer.
let size = array.size();
if (size == 0) {
- return;
+ return
};
let scratchSpace = Prim.Array_init(size, array[0]);
@@ -238,10 +238,10 @@ module {
var leftStart = 0; // selects the current left subarray being merged
while (leftStart < sizeDec) {
let mid : Nat = if (leftStart + currSize - 1 : Nat < sizeDec) {
- leftStart + currSize - 1;
+ leftStart + currSize - 1
} else { sizeDec };
let rightEnd : Nat = if (leftStart + (2 * currSize) - 1 : Nat < sizeDec) {
- leftStart + (2 * currSize) - 1;
+ leftStart + (2 * currSize) - 1
} else { sizeDec };
// Merge subarrays elements[leftStart...mid] and elements[mid+1...rightEnd]
@@ -254,37 +254,37 @@ module {
switch (compare(leftElement, rightElement)) {
case (#less or #equal) {
scratchSpace[nextSorted] := leftElement;
- left += 1;
+ left += 1
};
case (#greater) {
scratchSpace[nextSorted] := rightElement;
- right += 1;
- };
+ right += 1
+ }
};
- nextSorted += 1;
+ nextSorted += 1
};
while (left < mid + 1) {
scratchSpace[nextSorted] := array[left];
nextSorted += 1;
- left += 1;
+ left += 1
};
while (right < rightEnd + 1) {
scratchSpace[nextSorted] := array[right];
nextSorted += 1;
- right += 1;
+ right += 1
};
// Copy over merged elements
var i = leftStart;
while (i < rightEnd + 1) {
array[i] := scratchSpace[i];
- i += 1;
+ i += 1
};
- leftStart += 2 * currSize;
+ leftStart += 2 * currSize
};
- currSize *= 2;
- };
+ currSize *= 2
+ }
};
/// Creates a new array by reversing the order of elements in `array`.
@@ -301,7 +301,7 @@ module {
/// Space: O(1)
public func reverse(array : [X]) : [X] {
let size = array.size();
- Prim.Array_tabulate(size, func i = array[size - i - 1]);
+ Prim.Array_tabulate(size, func i = array[size - i - 1])
};
/// Creates a new array by applying `f` to each element in `array`. `f` "maps"
@@ -339,23 +339,23 @@ module {
func i {
if (predicate(array[i])) {
count += 1;
- true;
+ true
} else {
- false;
- };
- },
+ false
+ }
+ }
);
var nextKeep = 0;
Prim.Array_tabulate(
count,
func _ {
while (not keep[nextKeep]) {
- nextKeep += 1;
+ nextKeep += 1
};
nextKeep += 1;
- array[nextKeep - 1];
- },
- );
+ array[nextKeep - 1]
+ }
+ )
};
// FIXME the arguments ordering to the higher order function are flipped
@@ -403,13 +403,13 @@ module {
switch (result) {
case (?element) {
count += 1;
- result;
+ result
};
case null {
- null;
- };
- };
- },
+ null
+ }
+ }
+ }
);
var nextSome = 0;
@@ -417,17 +417,17 @@ module {
count,
func _ {
while (Option.isNull(options[nextSome])) {
- nextSome += 1;
+ nextSome += 1
};
nextSome += 1;
switch (options[nextSome - 1]) {
case (?element) element;
case null {
- Prim.trap "Malformed array in mapFilter";
- };
- };
- },
- );
+ Prim.trap "Malformed array in mapFilter"
+ }
+ }
+ }
+ )
};
/// Creates a new array by applying `f` to each element in `array`.
@@ -462,20 +462,20 @@ module {
func i {
switch (f(array[i])) {
case (#ok element) {
- ?element;
+ ?element
};
case (#err e) {
switch (error) {
case null {
// only take the first error
- error := ?(#err e);
+ error := ?(#err e)
};
- case _ {};
+ case _ {}
};
- null;
- };
- };
- },
+ null
+ }
+ }
+ }
);
switch error {
@@ -487,20 +487,20 @@ module {
func element {
switch element {
case (?element) {
- element;
+ element
};
case null {
- Prim.trap "Malformed array in mapResults";
- };
- };
- },
- ),
- );
+ Prim.trap "Malformed array in mapResults"
+ }
+ }
+ }
+ )
+ )
};
case (?error) {
- error;
- };
- };
+ error
+ }
+ }
};
/// Creates a new array by applying `k` to each element in `array`,
@@ -525,8 +525,8 @@ module {
func i {
let subArray = k(array[i]);
flatSize += subArray.size();
- subArray;
- },
+ subArray
+ }
);
// could replace with a call to flatten,
// but it would require an extra pass (to compute `flatSize`)
@@ -540,11 +540,11 @@ module {
inner += 1;
if (inner == subArray.size()) {
inner := 0;
- outer += 1;
+ outer += 1
};
- element;
- },
- );
+ element
+ }
+ )
};
/// Collapses the elements in `array` into a single value by starting with `base`
@@ -572,10 +572,10 @@ module {
var accumulation = base;
for (element in array.vals()) {
- accumulation := combine(accumulation, element);
+ accumulation := combine(accumulation, element)
};
- accumulation;
+ accumulation
};
// FIXME the type arguments are reverse order from Buffer
@@ -602,10 +602,10 @@ module {
var i = size;
while (i > 0) {
i -= 1;
- accumulation := combine(array[i], accumulation);
+ accumulation := combine(array[i], accumulation)
};
- accumulation;
+ accumulation
};
/// Flattens the array of arrays into a single array. Retains the original
@@ -623,7 +623,7 @@ module {
public func flatten(arrays : [[X]]) : [X] {
var flatSize = 0;
for (subArray in arrays.vals()) {
- flatSize += subArray.size();
+ flatSize += subArray.size()
};
var outer = 0;
@@ -633,13 +633,13 @@ module {
func _ {
while (inner == arrays[outer].size()) {
inner := 0;
- outer += 1;
+ outer += 1
};
let element = arrays[outer][inner];
inner += 1;
- element;
- },
- );
+ element
+ }
+ )
};
/// Create an array containing a single value.
@@ -697,5 +697,5 @@ module {
/// Runtime: O(1)
///
/// Space: O(1)
- public func keys(array : [X]) : I.Iter = array.keys();
-};
+ public func keys(array : [X]) : I.Iter = array.keys()
+}
diff --git a/src/AssocList.mo b/src/AssocList.mo
index a43165c3..af57431d 100644
--- a/src/AssocList.mo
+++ b/src/AssocList.mo
@@ -14,7 +14,7 @@ module {
public func find(
al : AssocList,
k : K,
- k_eq : (K, K) -> Bool,
+ k_eq : (K, K) -> Bool
) : ?V {
func rec(al : AssocList) : ?V {
label profile_assocList_find_rec : (?V) switch (al) {
@@ -22,17 +22,17 @@ module {
case (?((hd_k, hd_v), tl)) {
if (k_eq(k, hd_k)) {
label profile_assocList_find_end_success : (?V) {
- ?hd_v;
- };
+ ?hd_v
+ }
} else {
- rec(tl);
- };
- };
- };
+ rec(tl)
+ }
+ }
+ }
};
label profile_assocList_find_begin : (?V) {
- rec(al);
- };
+ rec(al)
+ }
};
/// replace the value associated with a given key, or add it, if missing.
@@ -41,15 +41,15 @@ module {
al : AssocList,
k : K,
k_eq : (K, K) -> Bool,
- ov : ?V,
+ ov : ?V
) : (AssocList, ?V) {
func rec(al : AssocList) : (AssocList, ?V) {
switch (al) {
case (null) {
switch ov {
case (null) { (null, null) };
- case (?v) { (?((k, v), null), null) };
- };
+ case (?v) { (?((k, v), null), null) }
+ }
};
case (?((hd_k, hd_v), tl)) {
if (k_eq(k, hd_k)) {
@@ -57,16 +57,16 @@ module {
// return old value
switch ov {
case (null) { (tl, ?hd_v) };
- case (?v) { (?((hd_k, v), tl), ?hd_v) };
- };
+ case (?v) { (?((hd_k, v), tl), ?hd_v) }
+ }
} else {
let (tl2, old_v) = rec(tl);
- (?((hd_k, hd_v), tl2), old_v);
- };
- };
- };
+ (?((hd_k, hd_v), tl2), old_v)
+ }
+ }
+ }
};
- rec(al);
+ rec(al)
};
/// The entries of the final list consist of those pairs of
@@ -75,7 +75,7 @@ module {
public func diff(
al1 : AssocList,
al2 : AssocList,
- keq : (K, K) -> Bool,
+ keq : (K, K) -> Bool
) : AssocList {
func rec(al1 : AssocList) : AssocList {
switch al1 {
@@ -83,37 +83,37 @@ module {
case (?((k, v1), tl)) {
switch (find(al2, k, keq)) {
case (null) { ?((k, v1), rec(tl)) };
- case (?v2) { rec(tl) };
- };
- };
- };
+ case (?v2) { rec(tl) }
+ }
+ }
+ }
};
- rec(al1);
+ rec(al1)
};
/// Transform and combine the entries of two association lists.
public func mapAppend(
al1 : AssocList,
al2 : AssocList,
- vbin : (?V, ?W) -> X,
+ vbin : (?V, ?W) -> X
) : AssocList = label profile_assocList_mapAppend : AssocList {
func rec(al1 : AssocList, al2 : AssocList) : AssocList = label profile_assocList_mapAppend_rec : AssocList {
switch (al1, al2) {
case (null, null) { null };
case (?((k, v), al1_), _) { ?((k, vbin(?v, null)), rec(al1_, al2)) };
- case (null, ?((k, v), al2_)) { ?((k, vbin(null, ?v)), rec(null, al2_)) };
- };
+ case (null, ?((k, v), al2_)) { ?((k, vbin(null, ?v)), rec(null, al2_)) }
+ }
};
- rec(al1, al2);
+ rec(al1, al2)
};
/// Specialized version of `disj`, optimized for disjoint sub-spaces of keyspace (no matching keys).
public func disjDisjoint(
al1 : AssocList,
al2 : AssocList,
- vbin : (?V, ?W) -> X,
+ vbin : (?V, ?W) -> X
) : AssocList = label profile_assocList_disjDisjoint : AssocList {
- mapAppend(al1, al2, vbin);
+ mapAppend(al1, al2, vbin)
};
/// This operation generalizes the notion of "set union" to finite maps.
@@ -128,7 +128,7 @@ module {
al1 : AssocList,
al2 : AssocList,
keq : (K, K) -> Bool,
- vbin : (?V, ?W) -> X,
+ vbin : (?V, ?W) -> X
) : AssocList {
func rec1(al1Rec : AssocList) : AssocList {
switch al1Rec {
@@ -139,22 +139,22 @@ module {
case (?((k, v2), tl)) {
switch (find(al1, k, keq)) {
case (null) { ?((k, vbin(null, ?v2)), rec2(tl)) };
- case (?v1) { ?((k, vbin(?v1, ?v2)), rec2(tl)) };
- };
- };
- };
+ case (?v1) { ?((k, vbin(?v1, ?v2)), rec2(tl)) }
+ }
+ }
+ }
};
- rec2(al2);
+ rec2(al2)
};
case (?((k, v1), tl)) {
switch (find(al2, k, keq)) {
case (null) { ?((k, vbin(?v1, null)), rec1(tl)) };
- case (?v2) { /* handled above */ rec1(tl) };
- };
- };
- };
+ case (?v2) { /* handled above */ rec1(tl) }
+ }
+ }
+ }
};
- rec1(al1);
+ rec1(al1)
};
/// This operation generalizes the notion of "set intersection" to
@@ -165,7 +165,7 @@ module {
al1 : AssocList,
al2 : AssocList,
keq : (K, K) -> Bool,
- vbin : (V, W) -> X,
+ vbin : (V, W) -> X
) : AssocList {
func rec(al1 : AssocList) : AssocList {
switch al1 {
@@ -173,27 +173,27 @@ module {
case (?((k, v1), tl)) {
switch (find(al2, k, keq)) {
case (null) { rec(tl) };
- case (?v2) { ?((k, vbin(v1, v2)), rec(tl)) };
- };
- };
- };
+ case (?v2) { ?((k, vbin(v1, v2)), rec(tl)) }
+ }
+ }
+ }
};
- rec(al1);
+ rec(al1)
};
/// Fold the entries based on the recursive list structure.
public func fold(
al : AssocList,
nil : X,
- cons : (K, V, X) -> X,
+ cons : (K, V, X) -> X
) : X {
func rec(al : AssocList) : X {
switch al {
case null { nil };
- case (?((k, v), t)) { cons(k, v, rec(t)) };
- };
+ case (?((k, v), t)) { cons(k, v, rec(t)) }
+ }
};
- rec(al);
+ rec(al)
};
-};
+}
diff --git a/src/Blob.mo b/src/Blob.mo
index 8d7b59a1..7c228d80 100644
--- a/src/Blob.mo
+++ b/src/Blob.mo
@@ -35,7 +35,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Blob, y : Blob) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
/// Creates a blob from an array of bytes, by copying each element.
@@ -50,4 +50,4 @@ module {
/// Creates a mutable array of bytes from a blob, by copying each element.
public let toArrayMut : Blob -> [var Nat8] = Prim.blobToArrayMut;
-};
+}
diff --git a/src/Bool.mo b/src/Bool.mo
index b70f8bdd..bb74545f 100644
--- a/src/Bool.mo
+++ b/src/Bool.mo
@@ -13,7 +13,7 @@ module {
/// Conversion.
public func toText(x : Bool) : Text {
- if x { "true" } else { "false" };
+ if x { "true" } else { "false" }
};
/// Returns `x and y`.
@@ -24,7 +24,7 @@ module {
/// Returns exclusive or of `x` and `y`, `x != y`.
public func logxor(x : Bool, y : Bool) : Bool {
- x != y;
+ x != y
};
/// Returns `not x`.
@@ -38,7 +38,7 @@ module {
/// Returns the order of `x` and `y`, where `false < true`.
public func compare(x : Bool, y : Bool) : { #less; #equal; #greater } {
- if (x == y) { #equal } else if (x) { #greater } else { #less };
+ if (x == y) { #equal } else if (x) { #greater } else { #less }
};
-};
+}
diff --git a/src/Buffer.mo b/src/Buffer.mo
index f2281676..251ca67c 100644
--- a/src/Buffer.mo
+++ b/src/Buffer.mo
@@ -57,11 +57,11 @@ module {
private func newCapacity(oldCapacity : Nat) : Nat {
if (oldCapacity == 0) {
- 1;
+ 1
} else {
// calculates ceil(oldCapacity * INCREASE_FACTOR) without floats
- ((oldCapacity * INCREASE_FACTOR_NUME) + INCREASE_FACTOR_DENOM - 1) / INCREASE_FACTOR_DENOM;
- };
+ ((oldCapacity * INCREASE_FACTOR_NUME) + INCREASE_FACTOR_DENOM - 1) / INCREASE_FACTOR_DENOM
+ }
};
public class Buffer(initCapacity : Nat) = this {
@@ -98,10 +98,10 @@ module {
/// Amortized Space: O(1), Worst Case Space: O(size)
public func add(element : X) {
if (_size == elements.size()) {
- reserve(newCapacity(elements.size()));
+ reserve(newCapacity(elements.size()))
};
elements[_size] := ?element;
- _size += 1;
+ _size += 1
};
/// Returns the element at index `index`. Traps if `index >= size`. Indexing is zero-based.
@@ -120,8 +120,8 @@ module {
public func get(index : Nat) : X {
switch (elements[index]) {
case (?element) element;
- case null Prim.trap("Buffer index out of bounds in get");
- };
+ case null Prim.trap("Buffer index out of bounds in get")
+ }
};
/// Returns the element at index `index` as an option.
@@ -141,10 +141,10 @@ module {
/// Space: O(1)
public func getOpt(index : Nat) : ?X {
if (index < _size) {
- elements[index];
+ elements[index]
} else {
- null;
- };
+ null
+ }
};
/// Overwrites the current element at `index` with `element`. Traps if
@@ -163,9 +163,9 @@ module {
/// Space: O(1)
public func put(index : Nat, element : X) {
if (index >= _size) {
- Prim.trap "Buffer index out of bounds in put";
+ Prim.trap "Buffer index out of bounds in put"
};
- elements[index] := ?element;
+ elements[index] := ?element
};
/// Removes and returns the last item in the buffer or `null` if
@@ -184,7 +184,7 @@ module {
/// Amortized Space: O(1), Worst Case Space: O(size)
public func removeLast() : ?X {
if (_size == 0) {
- return null;
+ return null
};
_size -= 1;
@@ -194,10 +194,10 @@ module {
if (_size < elements.size() / DECREASE_THRESHOLD) {
// FIXME should this new capacity be a function of _size
// instead of the current capacity? E.g. _size * INCREASE_FACTOR
- reserve(elements.size() / DECREASE_FACTOR);
+ reserve(elements.size() / DECREASE_FACTOR)
};
- lastElement;
+ lastElement
};
/// Removes and returns the element at `index` from the buffer.
@@ -225,7 +225,7 @@ module {
/// Amortized Space: O(1), Worst Case Space: O(size)
public func remove(index : Nat) : X {
if (index >= _size) {
- Prim.trap "Buffer index out of bounds in remove";
+ Prim.trap "Buffer index out of bounds in remove"
};
let element = elements[index];
@@ -239,34 +239,34 @@ module {
label l while (i < _size) {
if (i == index) {
i += 1;
- continue l;
+ continue l
};
elements2[j] := elements[i];
i += 1;
- j += 1;
+ j += 1
};
- elements := elements2;
+ elements := elements2
} else {
// just shift over elements
var i = index;
while (i < (_size - 1 : Nat)) {
elements[i] := elements[i + 1];
- i += 1;
+ i += 1
};
- elements[_size - 1] := null;
+ elements[_size - 1] := null
};
_size -= 1;
switch (element) {
case (?element) {
- element;
+ element
};
case null {
- Prim.trap "Malformed buffer in remove";
- };
- };
+ Prim.trap "Malformed buffer in remove"
+ }
+ }
};
/// Resets the buffer. Capacity is set to 8.
@@ -286,7 +286,7 @@ module {
/// Space: O(1)
public func clear() {
_size := 0;
- reserve(DEFAULT_CAPACITY);
+ reserve(DEFAULT_CAPACITY)
};
/// Removes all elements from the buffer for which the predicate returns false.
@@ -314,17 +314,17 @@ module {
switch (elements[i]) {
case (?element) {
if (predicate(i, element)) {
- true;
+ true
} else {
numRemoved += 1;
- false;
- };
+ false
+ }
};
case null {
- Prim.trap "Malformed buffer in filter()";
- };
- };
- },
+ Prim.trap "Malformed buffer in filter()"
+ }
+ }
+ }
);
let capacity = elements.size();
@@ -338,13 +338,13 @@ module {
if (keep[i]) {
elements2[j] := elements[i];
i += 1;
- j += 1;
+ j += 1
} else {
- i += 1;
- };
+ i += 1
+ }
};
- elements := elements2;
+ elements := elements2
} else {
var i = 0;
var j = 0;
@@ -352,19 +352,19 @@ module {
if (keep[i]) {
elements[j] := elements[i];
i += 1;
- j += 1;
+ j += 1
} else {
- i += 1;
- };
+ i += 1
+ }
};
while (j < _size) {
elements[j] := null;
- j += 1;
- };
+ j += 1
+ }
};
- _size -= numRemoved;
+ _size -= numRemoved
};
/// Returns the capacity of the buffer (the length of the underlying array).
@@ -400,7 +400,7 @@ module {
/// Space: O(capacity)
public func reserve(capacity : Nat) {
if (capacity < _size) {
- Prim.trap "capacity must be >= size in reserve";
+ Prim.trap "capacity must be >= size in reserve"
};
let elements2 = Prim.Array_init(capacity, null);
@@ -408,9 +408,9 @@ module {
var i = 0;
while (i < _size) {
elements2[i] := elements[i];
- i += 1;
+ i += 1
};
- elements := elements2;
+ elements := elements2
};
/// Adds all elements in buffer `b` to this buffer.
@@ -434,15 +434,15 @@ module {
// Make sure you only allocate a new array at most once
if (_size + size2 > elements.size()) {
// FIXME would be nice to have a tabulate for var arrays here
- reserve(newCapacity(_size + size2));
+ reserve(newCapacity(_size + size2))
};
var i = 0;
while (i < size2) {
elements[_size + i] := buffer2.getOpt i;
- i += 1;
+ i += 1
};
- _size += size2;
+ _size += size2
};
/// Inserts `element` at `index`, shifts all elements to the right of
@@ -462,7 +462,7 @@ module {
/// Amortized Space: O(1), Worst Case Space: O(size)
public func insert(index : Nat, element : X) {
if (index > _size) {
- Prim.trap "Buffer index out of bounds in insert";
+ Prim.trap "Buffer index out of bounds in insert"
};
let capacity = elements.size();
@@ -472,26 +472,26 @@ module {
var i = 0;
while (i < _size + 1) {
if (i < index) {
- elements2[i] := elements[i];
+ elements2[i] := elements[i]
} else if (i == index) {
- elements2[i] := ?element;
+ elements2[i] := ?element
} else {
- elements2[i] := elements[i - 1];
+ elements2[i] := elements[i - 1]
};
- i += 1;
+ i += 1
};
- elements := elements2;
+ elements := elements2
} else {
var i : Nat = _size;
while (i > index) {
elements[i] := elements[i - 1];
- i -= 1;
+ i -= 1
};
- elements[index] := ?element;
+ elements[index] := ?element
};
- _size += 1;
+ _size += 1
};
/// Inserts `buffer2` at `index`, and shifts all elements to the right of
@@ -513,7 +513,7 @@ module {
/// Amortized Space: O(1), Worst Case Space: O(size1 + size2)
public func insertBuffer(index : Nat, buffer2 : Buffer) {
if (index > _size) {
- Prim.trap "Buffer index out of bounds in insertBuffer";
+ Prim.trap "Buffer index out of bounds in insertBuffer"
};
let size2 = buffer2.size();
@@ -525,32 +525,32 @@ module {
var i = 0;
for (element in elements.vals()) {
if (i == index) {
- i += size2;
+ i += size2
};
elements2[i] := element;
- i += 1;
+ i += 1
};
i := 0;
while (i < size2) {
elements2[i + index] := buffer2.getOpt(i);
- i += 1;
+ i += 1
};
- elements := elements2;
+ elements := elements2
} // just insert
else {
var i = index;
while (i < index + size2) {
if (i < _size) {
- elements[i + size2] := elements[i];
+ elements[i + size2] := elements[i]
};
elements[i] := buffer2.getOpt(i - index);
- i += 1;
- };
+ i += 1
+ }
};
- _size += size2;
+ _size += size2
};
/// Sorts the elements in the buffer according to `compare`.
@@ -573,7 +573,7 @@ module {
public func sort(compare : (X, X) -> Order.Order) {
// Stable merge sort in a bottom-up iterative style
if (_size == 0) {
- return;
+ return
};
let scratchSpace = Prim.Array_init(_size, null);
@@ -584,10 +584,10 @@ module {
var leftStart = 0; // selects the current left subarray being merged
while (leftStart < sizeDec) {
let mid : Nat = if (leftStart + currSize - 1 : Nat < sizeDec) {
- leftStart + currSize - 1;
+ leftStart + currSize - 1
} else { sizeDec };
let rightEnd : Nat = if (leftStart + (2 * currSize) - 1 : Nat < sizeDec) {
- leftStart + (2 * currSize) - 1;
+ leftStart + (2 * currSize) - 1
} else { sizeDec };
// Merge subarrays elements[leftStart...mid] and elements[mid+1...rightEnd]
@@ -602,43 +602,43 @@ module {
switch (compare(leftElement, rightElement)) {
case (#less or #equal) {
scratchSpace[nextSorted] := leftOpt;
- left += 1;
+ left += 1
};
case (#greater) {
scratchSpace[nextSorted] := rightOpt;
- right += 1;
- };
- };
+ right += 1
+ }
+ }
};
case (_, _) {
// only sorting non-null items
- Prim.trap "Malformed buffer in sort";
- };
+ Prim.trap "Malformed buffer in sort"
+ }
};
- nextSorted += 1;
+ nextSorted += 1
};
while (left < mid + 1) {
scratchSpace[nextSorted] := elements[left];
nextSorted += 1;
- left += 1;
+ left += 1
};
while (right < rightEnd + 1) {
scratchSpace[nextSorted] := elements[right];
nextSorted += 1;
- right += 1;
+ right += 1
};
// Copy over merged elements
var i = leftStart;
while (i < rightEnd + 1) {
elements[i] := scratchSpace[i];
- i += 1;
+ i += 1
};
- leftStart += 2 * currSize;
+ leftStart += 2 * currSize
};
- currSize *= 2;
- };
+ currSize *= 2
+ }
};
/// Returns an Iterator (`Iter`) over the elements of this buffer.
@@ -667,12 +667,12 @@ module {
var nextIndex = 0;
public func next() : ?X {
if (nextIndex >= _size) {
- return null;
+ return null
};
let nextElement = elements[nextIndex];
nextIndex += 1;
- nextElement;
- };
+ nextElement
+ }
};
// FOLLOWING METHODS ARE DEPRECATED
@@ -681,9 +681,9 @@ module {
public func clone() : Buffer {
let newBuffer = Buffer(elements.size());
for (element in vals()) {
- newBuffer.add(element);
+ newBuffer.add(element)
};
- newBuffer;
+ newBuffer
};
/// @deprecated Use static library function instead.
@@ -691,7 +691,7 @@ module {
// immutable clone of array
Prim.Array_tabulate(
_size,
- func(i : Nat) : X { get i },
+ func(i : Nat) : X { get i }
);
/// @deprecated Use static library function instead.
@@ -701,11 +701,11 @@ module {
var i = 0;
for (element in vals()) {
newArray[i] := element;
- i += 1;
+ i += 1
};
- newArray;
- };
- };
+ newArray
+ }
+ }
};
/// Returns true iff the buffer is empty.
@@ -726,11 +726,11 @@ module {
public func contains(buffer : Buffer, element : X, equal : (X, X) -> Bool) : Bool {
for (current in buffer.vals()) {
if (equal(current, element)) {
- return true;
- };
+ return true
+ }
};
- false;
+ false
};
/// Returns a copy of `buffer`, with the same capacity.
@@ -741,9 +741,9 @@ module {
public func clone(buffer : Buffer) : Buffer {
let newBuffer = Buffer(buffer.capacity());
for (element in buffer.vals()) {
- newBuffer.add(element);
+ newBuffer.add(element)
};
- newBuffer;
+ newBuffer
};
/// Finds the greatest element in `buffer` defined by `compare`.
@@ -756,20 +756,20 @@ module {
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
public func max(buffer : Buffer, compare : (X, X) -> Order) : ?X {
if (buffer.size() == 0) {
- return null;
+ return null
};
var maxSoFar = buffer.get(0);
for (current in buffer.vals()) {
switch (compare(current, maxSoFar)) {
case (#greater) {
- maxSoFar := current;
+ maxSoFar := current
};
- case _ {};
- };
+ case _ {}
+ }
};
- ?maxSoFar;
+ ?maxSoFar
};
/// Finds the least element in `buffer` defined by `compare`.
@@ -782,20 +782,20 @@ module {
/// *Runtime and space assumes that `compare` runs in O(1) time and space.
public func min(buffer : Buffer, compare : (X, X) -> Order) : ?X {
if (buffer.size() == 0) {
- return null;
+ return null
};
var minSoFar = buffer.get(0);
for (current in buffer.vals()) {
switch (compare(current, minSoFar)) {
case (#less) {
- minSoFar := current;
+ minSoFar := current
};
- case _ {};
- };
+ case _ {}
+ }
};
- ?minSoFar;
+ ?minSoFar
};
/// Defines equality for two buffers, using `equal` to recursively compare elements in the
@@ -812,18 +812,18 @@ module {
let size1 = buffer1.size();
if (size1 != buffer2.size()) {
- return false;
+ return false
};
var i = 0;
while (i < size1) {
if (not equal(buffer1.get(i), buffer2.get(i))) {
- return false;
+ return false
};
- i += 1;
+ i += 1
};
- true;
+ true
};
/// Defines comparison for two buffers, using `compare` to recursively compare elements in the
@@ -843,23 +843,23 @@ module {
while (i < minSize) {
switch (compare(buffer1.get(i), buffer2.get(i))) {
case (#less) {
- return #less;
+ return #less
};
case (#greater) {
- return #greater;
+ return #greater
};
- case _ {};
+ case _ {}
};
- i += 1;
+ i += 1
};
if (size1 < size2) {
- #less;
+ #less
} else if (size1 == size2) {
- #equal;
+ #equal
} else {
- #greater;
- };
+ #greater
+ }
};
/// Creates a textual representation of `buffer`, using `toText` to recursively
@@ -876,14 +876,14 @@ module {
var text = "";
while (i < size - 1) {
text := text # toText(buffer.get(i)) # ", "; // Text implemented as rope
- i += 1;
+ i += 1
};
if (size > 0) {
// avoid the trailing comma
- text := text # toText(buffer.get(i));
+ text := text # toText(buffer.get(i))
};
- "[" # text # "]";
+ "[" # text # "]"
};
/// Hashes `buffer` using `hash` to hash the underlying elements.
@@ -902,10 +902,10 @@ module {
while (i < size) {
accHash := Prim.intToNat32Wrap(i) ^ accHash ^ hash(buffer.get(i));
- i += 1;
+ i += 1
};
- accHash;
+ accHash
};
/// Finds the first index of `element` in `buffer` using equality of elements defined
@@ -921,12 +921,12 @@ module {
var i = 0;
while (i < size) {
if (equal(buffer.get(i), element)) {
- return ?i;
+ return ?i
};
- i += 1;
+ i += 1
};
- null;
+ null
};
/// Finds the last index of `element` in `buffer` using equality of elements defined
@@ -940,17 +940,17 @@ module {
public func lastIndexOf(element : X, buffer : Buffer, equal : (X, X) -> Bool) : ?Nat {
let size = buffer.size();
if (size == 0) {
- return null;
+ return null
};
var i = size;
while (i >= 1) {
i -= 1;
if (equal(buffer.get(i), element)) {
- return ?i;
- };
+ return ?i
+ }
};
- null;
+ null
};
/// Searches for `subBuffer` in `buffer`, and returns the starting index if it is found.
@@ -966,7 +966,7 @@ module {
let size = buffer.size();
let subSize = subBuffer.size();
if (subSize > size or subSize == 0) {
- return null;
+ return null
};
// precompute lps
@@ -978,13 +978,13 @@ module {
if (equal(subBuffer.get(i), subBuffer.get(j))) {
i += 1;
lps[j] := i;
- j += 1;
+ j += 1
} else if (i == 0) {
lps[j] := 0;
- j += 1;
+ j += 1
} else {
- i := lps[i - 1];
- };
+ i := lps[i - 1]
+ }
};
// start search
@@ -993,20 +993,20 @@ module {
let subSizeDec = subSize - 1 : Nat; // hoisting loop invariant
while (i < subSize and j < size) {
if (equal(subBuffer.get(i), buffer.get(j)) and i == subSizeDec) {
- return ?(j - i);
+ return ?(j - i)
} else if (equal(subBuffer.get(i), buffer.get(j))) {
i += 1;
- j += 1;
+ j += 1
} else {
if (i != 0) {
- i := lps[i - 1];
+ i := lps[i - 1]
} else {
- j += 1;
- };
- };
+ j += 1
+ }
+ }
};
- null;
+ null
};
/// Similar to indexOf, but runs in logarithmic time. Assumes that `buffer` is sorted.
@@ -1027,18 +1027,18 @@ module {
let current = buffer.get(mid);
switch (compare(element, current)) {
case (#equal) {
- return ?mid;
+ return ?mid
};
case (#less) {
- high := mid;
+ high := mid
};
case (#greater) {
- low := mid + 1;
- };
- };
+ low := mid + 1
+ }
+ }
};
- null;
+ null
};
/// Returns the sub-buffer of `buffer` starting at index `start`
@@ -1052,7 +1052,7 @@ module {
let size = buffer.size();
let end = start + length; // exclusive
if (start >= size or end > size) {
- Prim.trap "Buffer index out of bounds in subBuffer";
+ Prim.trap "Buffer index out of bounds in subBuffer"
};
let newBuffer = Buffer(newCapacity length);
@@ -1061,10 +1061,10 @@ module {
while (i < end) {
newBuffer.add(buffer.get(i));
- i += 1;
+ i += 1
};
- newBuffer;
+ newBuffer
};
/// Checks if `subBuffer` is a sub-Buffer of `buffer`. Uses `equal` to
@@ -1078,8 +1078,8 @@ module {
public func isSubBufferOf(subBuffer : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool {
switch (indexOfBuffer(subBuffer, buffer, equal)) {
case null subBuffer.size() == 0;
- case _ true;
- };
+ case _ true
+ }
};
/// Checks if `subBuffer` is a strict subBuffer of `buffer`, i.e. `subBuffer` must be
@@ -1099,9 +1099,9 @@ module {
index != 0 and index != (buffer.size() - subBufferSize : Nat) // enforce strictness
};
case null {
- subBufferSize == 0 and subBufferSize != buffer.size();
- };
- };
+ subBufferSize == 0 and subBufferSize != buffer.size()
+ }
+ }
};
/// Returns the prefix of `buffer` of length `length`. Traps if `length`
@@ -1113,7 +1113,7 @@ module {
public func prefix(buffer : Buffer, length : Nat) : Buffer {
let size = buffer.size();
if (length > size) {
- Prim.trap "Buffer index out of bounds in prefix";
+ Prim.trap "Buffer index out of bounds in prefix"
};
let newBuffer = Buffer(newCapacity length);
@@ -1121,10 +1121,10 @@ module {
var i = 0;
while (i < length) {
newBuffer.add(buffer.get(i));
- i += 1;
+ i += 1
};
- newBuffer;
+ newBuffer
};
/// Checks if `prefix` is a prefix of `buffer`. Uses `equal` to
@@ -1138,19 +1138,19 @@ module {
public func isPrefixOf(prefix : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool {
let sizePrefix = prefix.size();
if (buffer.size() < sizePrefix) {
- return false;
+ return false
};
var i = 0;
while (i < sizePrefix) {
if (not equal(buffer.get(i), prefix.get(i))) {
- return false;
+ return false
};
- i += 1;
+ i += 1
};
- return true;
+ return true
};
/// Checks if `prefix` is a strict prefix of `buffer`. Uses `equal` to
@@ -1163,9 +1163,9 @@ module {
/// *Runtime and space assumes that `equal` runs in O(1) time and space.
public func isStrictPrefixOf(prefix : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool {
if (buffer.size() <= prefix.size()) {
- return false;
+ return false
};
- isPrefixOf(prefix, buffer, equal);
+ isPrefixOf(prefix, buffer, equal)
};
/// Returns the suffix of `buffer` of length `length`.
@@ -1178,7 +1178,7 @@ module {
let size = buffer.size();
if (length > size) {
- Prim.trap "Buffer index out of bounds in suffix";
+ Prim.trap "Buffer index out of bounds in suffix"
};
let newBuffer = Buffer(newCapacity length);
@@ -1187,10 +1187,10 @@ module {
while (i < size) {
newBuffer.add(buffer.get(i));
- i += 1;
+ i += 1
};
- newBuffer;
+ newBuffer
};
/// Checks if `suffix` is a suffix of `buffer`. Uses `equal` to compare
@@ -1205,7 +1205,7 @@ module {
let suffixSize = suffix.size();
let bufferSize = buffer.size();
if (bufferSize < suffixSize) {
- return false;
+ return false
};
var i = bufferSize;
@@ -1214,11 +1214,11 @@ module {
i -= 1;
j -= 1;
if (not equal(buffer.get(i), suffix.get(j))) {
- return false;
- };
+ return false
+ }
};
- return true;
+ return true
};
/// Checks if `suffix` is a strict suffix of `buffer`. Uses `equal` to compare
@@ -1231,9 +1231,9 @@ module {
/// *Runtime and space assumes that `equal` runs in O(1) time and space.
public func isStrictSuffixOf(suffix : Buffer, buffer : Buffer, equal : (X, X) -> Bool) : Bool {
if (buffer.size() <= suffix.size()) {
- return false;
+ return false
};
- isSuffixOf(suffix, buffer, equal);
+ isSuffixOf(suffix, buffer, equal)
};
/// Returns true iff every element in `buffer` satisfies `predicate`.
@@ -1246,11 +1246,11 @@ module {
public func forAll(buffer : Buffer, predicate : X -> Bool) : Bool {
for (element in buffer.vals()) {
if (not predicate element) {
- return false;
- };
+ return false
+ }
};
- true;
+ true
};
/// Returns true iff some element in `buffer` satisfies `predicate`.
@@ -1263,11 +1263,11 @@ module {
public func forSome(buffer : Buffer, predicate : X -> Bool) : Bool {
for (element in buffer.vals()) {
if (predicate element) {
- return true;
- };
+ return true
+ }
};
- false;
+ false
};
/// Returns true iff no element in `buffer` satisfies `predicate`.
@@ -1280,11 +1280,11 @@ module {
public func forNone(buffer : Buffer, predicate : X -> Bool) : Bool {
for (element in buffer.vals()) {
if (predicate element) {
- return false;
- };
+ return false
+ }
};
- true;
+ true
};
/// Creates an array containing elements from `buffer`.
@@ -1296,7 +1296,7 @@ module {
// immutable clone of array
Prim.Array_tabulate(
buffer.size(),
- func(i : Nat) : X { buffer.get(i) },
+ func(i : Nat) : X { buffer.get(i) }
);
/// Creates a mutable array containing elements from `buffer`.
@@ -1311,10 +1311,10 @@ module {
var i = 1;
while (i < size) {
newArray[i] := buffer.get(i);
- i += 1;
+ i += 1
};
- newArray;
- };
+ newArray
+ }
};
/// Creates a buffer containing elements from `array`.
@@ -1333,10 +1333,10 @@ module {
let newBuffer = Buffer(newCapacity(array.size()));
for (element in array.vals()) {
- newBuffer.add(element);
+ newBuffer.add(element)
};
- newBuffer;
+ newBuffer
};
/// Creates a buffer containing elements from `array`.
@@ -1348,10 +1348,10 @@ module {
let newBuffer = Buffer(newCapacity(array.size()));
for (element in array.vals()) {
- newBuffer.add(element);
+ newBuffer.add(element)
};
- newBuffer;
+ newBuffer
};
/// Creates a buffer containing elements from `iter`.
@@ -1363,10 +1363,10 @@ module {
let newBuffer = Buffer(DEFAULT_CAPACITY); // can't get size from `iter`
for (element in iter) {
- newBuffer.add(element);
+ newBuffer.add(element)
};
- newBuffer;
+ newBuffer
};
/// Reallocates the array underlying `buffer` such that capacity == size.
@@ -1377,8 +1377,8 @@ module {
public func trimToSize(buffer : Buffer) {
let size = buffer.size();
if (size < buffer.capacity()) {
- buffer.reserve(size);
- };
+ buffer.reserve(size)
+ }
};
/// Creates a new buffer by applying `f` to each element in `buffer`.
@@ -1392,10 +1392,10 @@ module {
let newBuffer = Buffer(buffer.capacity());
for (element in buffer.vals()) {
- newBuffer.add(f element);
+ newBuffer.add(f element)
};
- newBuffer;
+ newBuffer
};
/// Applies `f` to each element in `buffer`.
@@ -1407,8 +1407,8 @@ module {
/// *Runtime and space assumes that `f` runs in O(1) time and space.
public func iterate(buffer : Buffer, f : X -> ()) {
for (element in buffer.vals()) {
- f element;
- };
+ f element
+ }
};
/// Applies `f` to each element in `buffer` and its index.
@@ -1425,10 +1425,10 @@ module {
let size = buffer.size();
while (i < size) {
newBuffer.add(f(i, buffer.get(i)));
- i += 1;
+ i += 1
};
- newBuffer;
+ newBuffer
};
/// Creates a new buffer by applying `f` to each element in `buffer`,
@@ -1445,13 +1445,13 @@ module {
for (element in buffer.vals()) {
switch (f element) {
case (?element) {
- newBuffer.add(element);
+ newBuffer.add(element)
};
- case _ {};
- };
+ case _ {}
+ }
};
- newBuffer;
+ newBuffer
};
/// Creates a new buffer by applying `f` to each element in `buffer`.
@@ -1469,15 +1469,15 @@ module {
for (element in buffer.vals()) {
switch (f element) {
case (#ok result) {
- newBuffer.add(result);
+ newBuffer.add(result)
};
case (#err e) {
- return #err e;
- };
- };
+ return #err e
+ }
+ }
};
- #ok newBuffer;
+ #ok newBuffer
};
/// Creates a new buffer by applying `k` to each element in `buffer`,
@@ -1493,10 +1493,10 @@ module {
let newBuffer = Buffer(buffer.size() * 4);
for (element in buffer.vals()) {
- newBuffer.append(k element);
+ newBuffer.append(k element)
};
- newBuffer;
+ newBuffer
};
/// Collapses the elements in `buffer` into a single value by starting with `base`
@@ -1512,10 +1512,10 @@ module {
var accumulation = base;
for (element in buffer.vals()) {
- accumulation := combine(accumulation, element);
+ accumulation := combine(accumulation, element)
};
- accumulation;
+ accumulation
};
/// Collapses the elements in `buffer` into a single value by starting with `base`
@@ -1530,17 +1530,17 @@ module {
public func foldRight(buffer : Buffer, base : A, combine : (X, A) -> A) : A {
let size = buffer.size();
if (size == 0) {
- return base;
+ return base
};
var accumulation = base;
var i = size;
while (i >= 1) {
i -= 1; // to avoid Nat underflow, subtract first and stop iteration at 1
- accumulation := combine(buffer.get(i), accumulation);
+ accumulation := combine(buffer.get(i), accumulation)
};
- accumulation;
+ accumulation
};
/// Returns the first element of `buffer`. Traps if `buffer` is empty.
@@ -1565,7 +1565,7 @@ module {
public func make(element : X) : Buffer {
let newBuffer = Buffer(1);
newBuffer.add(element);
- newBuffer;
+ newBuffer
};
/// Reverses the order of elements in `buffer`.
@@ -1576,7 +1576,7 @@ module {
public func reverse(buffer : Buffer) {
let size = buffer.size();
if (size == 0) {
- return;
+ return
};
var i = 0;
@@ -1587,8 +1587,8 @@ module {
buffer.put(j, buffer.get(i));
buffer.put(i, temp);
i += 1;
- j -= 1;
- };
+ j -= 1
+ }
};
/// Merges two sorted buffers into a single sorted buffer, using `compare` to define
@@ -1616,26 +1616,26 @@ module {
switch (compare(current1, current2)) {
case (#less) {
newBuffer.add(current1);
- pointer1 += 1;
+ pointer1 += 1
};
case _ {
newBuffer.add(current2);
- pointer2 += 1;
- };
- };
+ pointer2 += 1
+ }
+ }
};
while (pointer1 < size1) {
newBuffer.add(buffer1.get(pointer1));
- pointer1 += 1;
+ pointer1 += 1
};
while (pointer2 < size2) {
newBuffer.add(buffer2.get(pointer2));
- pointer2 += 1;
+ pointer2 += 1
};
- newBuffer;
+ newBuffer
};
/// Eliminates all duplicate elements in `buffer` as defined by `compare`.
@@ -1664,38 +1664,38 @@ module {
switch (compare(pair1.1, pair2.1)) {
case (#equal) {
if (pair2.0 < pair1.0) {
- minIndex := pair2;
+ minIndex := pair2
};
- j += 1;
+ j += 1
};
case _ {
- break duplicates;
- };
- };
+ break duplicates
+ }
+ }
};
uniques.add(minIndex);
- i := j + 1;
+ i := j + 1
};
// resort based on original ordering and place back in buffer
uniques.sort(
func(pair1, pair2) {
if (pair1.0 < pair2.0) {
- #less;
+ #less
} else if (pair1.0 == pair2.0) {
- #equal;
+ #equal
} else {
- #greater;
- };
- },
+ #greater
+ }
+ }
);
buffer.clear();
buffer.reserve(uniques.size());
for (element in uniques.vals()) {
- buffer.add(element.1);
- };
+ buffer.add(element.1)
+ }
};
/// Splits `buffer` into a pair of buffers where all elements in the left
@@ -1713,13 +1713,13 @@ module {
for (element in buffer.vals()) {
if (predicate element) {
- trueBuffer.add(element);
+ trueBuffer.add(element)
} else {
- falseBuffer.add(element);
- };
+ falseBuffer.add(element)
+ }
};
- (trueBuffer, falseBuffer);
+ (trueBuffer, falseBuffer)
};
/// Splits the buffer into two buffers at `index`, where the left buffer contains
@@ -1736,7 +1736,7 @@ module {
let size = buffer.size();
if (index < 0 or index > size) {
- Prim.trap "Index out of bounds in split";
+ Prim.trap "Index out of bounds in split"
};
let buffer1 = Buffer(newCapacity index);
@@ -1745,14 +1745,14 @@ module {
var i = 0;
while (i < index) {
buffer1.add(buffer.get(i));
- i += 1;
+ i += 1
};
while (i < size) {
buffer2.add(buffer.get(i));
- i += 1;
+ i += 1
};
- (buffer1, buffer2);
+ (buffer1, buffer2)
};
/// Breaks up `buffer` into buffers of size `size`. The last chunk may
@@ -1764,7 +1764,7 @@ module {
/// Space: O(number of elements in buffer)
public func chunk(buffer : Buffer, size : Nat) : Buffer> {
if (size == 0) {
- Prim.trap "Chunk size must be non-zero in chunk";
+ Prim.trap "Chunk size must be non-zero in chunk"
};
// ceil(buffer.size() / size)
@@ -1776,16 +1776,16 @@ module {
if (innerSize == size) {
newBuffer.add(newInnerBuffer);
newInnerBuffer := Buffer(newCapacity size);
- innerSize := 0;
+ innerSize := 0
};
newInnerBuffer.add(element);
- innerSize += 1;
+ innerSize += 1
};
if (innerSize > 0) {
- newBuffer.add(newInnerBuffer);
+ newBuffer.add(newInnerBuffer)
};
- newBuffer;
+ newBuffer
};
/// Groups equal and adjacent elements in the list into sub lists.
@@ -1799,7 +1799,7 @@ module {
let size = buffer.size();
let newBuffer = Buffer>(size);
if (size == 0) {
- return newBuffer;
+ return newBuffer
};
var i = 0;
@@ -1809,20 +1809,20 @@ module {
let element = buffer.get(i);
if (equal(baseElement, element)) {
- newInnerBuffer.add(element);
+ newInnerBuffer.add(element)
} else {
newBuffer.add(newInnerBuffer);
baseElement := element;
newInnerBuffer := Buffer(size - i);
- newInnerBuffer.add(element);
+ newInnerBuffer.add(element)
};
- i += 1;
+ i += 1
};
if (newInnerBuffer.size() > 0) {
- newBuffer.add(newInnerBuffer);
+ newBuffer.add(newInnerBuffer)
};
- newBuffer;
+ newBuffer
};
/// Flattens the buffer of buffers into a single buffer.
@@ -1833,24 +1833,24 @@ module {
public func flatten(buffer : Buffer>) : Buffer {
let size = buffer.size();
if (size == 0) {
- return Buffer(0);
+ return Buffer(0)
};
let newBuffer = Buffer(
if (buffer.get(0).size() != 0) {
- newCapacity(buffer.get(0).size() * size);
+ newCapacity(buffer.get(0).size() * size)
} else {
- newCapacity(size);
- },
+ newCapacity(size)
+ }
);
for (innerBuffer in buffer.vals()) {
for (innerElement in innerBuffer.vals()) {
- newBuffer.add(innerElement);
- };
+ newBuffer.add(innerElement)
+ }
};
- newBuffer;
+ newBuffer
};
/// Combines the two buffers into a single buffer of pairs, pairing together
@@ -1862,7 +1862,7 @@ module {
/// Space: O(min(size1, size2))
public func zip(buffer1 : Buffer, buffer2 : Buffer) : Buffer<(X, Y)> {
// compiler should pull lamda out as a static function since it is fully closed
- zipWith(buffer1, buffer2, func(x, y) = (x, y));
+ zipWith(buffer1, buffer2, func(x, y) = (x, y))
};
/// Combines the two buffers into a single buffer, pairing together
@@ -1884,9 +1884,9 @@ module {
let newBuffer = Buffer(newCapacity minSize);
while (i < minSize) {
newBuffer.add(zip(buffer1.get(i), buffer2.get(i)));
- i += 1;
+ i += 1
};
- newBuffer;
+ newBuffer
};
/// Creates a new buffer taking elements in order from `buffer` until predicate
@@ -1902,12 +1902,12 @@ module {
for (element in buffer.vals()) {
if (not predicate element) {
- return newBuffer;
+ return newBuffer
};
- newBuffer.add(element);
+ newBuffer.add(element)
};
- newBuffer;
+ newBuffer
};
/// Creates a new buffer excluding elements in order from `buffer` until predicate
@@ -1926,12 +1926,12 @@ module {
var take = false;
label iter for (element in buffer.vals()) {
if (not (take or predicate element)) {
- take := true;
+ take := true
};
if (take) {
- newBuffer.add(element);
- };
+ newBuffer.add(element)
+ }
};
- newBuffer;
- };
-};
+ newBuffer
+ }
+}
diff --git a/src/CertifiedData.mo b/src/CertifiedData.mo
index b66ba498..6442c369 100644
--- a/src/CertifiedData.mo
+++ b/src/CertifiedData.mo
@@ -26,4 +26,4 @@ module {
/// when processing a query call.
public let getCertificate : () -> ?Blob = Prim.getCertificate;
-};
+}
diff --git a/src/Char.mo b/src/Char.mo
index 94b3d817..d4ef02fc 100644
--- a/src/Char.mo
+++ b/src/Char.mo
@@ -24,7 +24,7 @@ module {
/// Returns `true` when `c` is a decimal digit between `0` and `9`, otherwise `false`.
public func isDigit(c : Char) : Bool {
- Prim.charToNat32(c) -% Prim.charToNat32('0') <= (9 : Nat32);
+ Prim.charToNat32(c) -% Prim.charToNat32('0') <= (9 : Nat32)
};
/// Returns the Unicode _White_Space_ property of `c`.
@@ -59,7 +59,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Char, y : Char) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
-};
+}
diff --git a/src/Debug.mo b/src/Debug.mo
index 33f26ba6..f104e2c1 100644
--- a/src/Debug.mo
+++ b/src/Debug.mo
@@ -11,4 +11,4 @@ module {
/// `trap(t)` traps execution with a user-provided message.
public let trap : Text -> None = Prim.trap;
-};
+}
diff --git a/src/Deque.mo b/src/Deque.mo
index f1257b68..4de102b0 100644
--- a/src/Deque.mo
+++ b/src/Deque.mo
@@ -15,27 +15,27 @@ module {
/// True when the queue is empty
public func isEmpty(q : Deque) : Bool {
switch q {
- case (f, r) { List.isNil(f) and List.isNil(r) };
- };
+ case (f, r) { List.isNil(f) and List.isNil(r) }
+ }
};
func check(q : Deque) : Deque {
switch q {
case (null, r) {
let (a, b) = List.split(List.size(r) / 2, r);
- (List.reverse(b), a);
+ (List.reverse(b), a)
};
case (f, null) {
let (a, b) = List.split(List.size(f) / 2, f);
- (a, List.reverse(b));
+ (a, List.reverse(b))
};
- case q { q };
- };
+ case q { q }
+ }
};
/// Insert a new element on the front end of the queue
public func pushFront(q : Deque, x : T) : Deque {
- check(List.push(x, q.0), q.1);
+ check(List.push(x, q.0), q.1)
};
/// Inspect the (optional) first element on the front end of the queue
@@ -43,8 +43,8 @@ module {
switch q {
case (?(x, f), r) { ?x };
case (null, ?(x, r)) { ?x };
- case _ { null };
- };
+ case _ { null }
+ }
};
/// Remove the first element on the front end of the queue; Returns null when empty.
@@ -52,13 +52,13 @@ module {
switch q {
case (?(x, f), r) { ?(x, check(f, r)) };
case (null, ?(x, r)) { ?(x, check(null, r)) };
- case _ { null };
- };
+ case _ { null }
+ }
};
/// Insert a new element on the back end of the queue
public func pushBack(q : Deque, x : T) : Deque {
- check(q.0, List.push(x, q.1));
+ check(q.0, List.push(x, q.1))
};
/// Inspect the (optional) first element on the back end of the queue
@@ -66,8 +66,8 @@ module {
switch q {
case (f, ?(x, r)) { ?x };
case (?(x, r), null) { ?x };
- case _ { null };
- };
+ case _ { null }
+ }
};
/// Remove the first element on the back end of the queue; Returns null when empty.
@@ -75,7 +75,7 @@ module {
switch q {
case (f, ?(x, r)) { ?(check(f, r), x) };
case (?(x, f), null) { ?(check(f, null), x) };
- case _ { null };
- };
- };
-};
+ case _ { null }
+ }
+ }
+}
diff --git a/src/Error.mo b/src/Error.mo
index 439ae35b..0a7dcec1 100644
--- a/src/Error.mo
+++ b/src/Error.mo
@@ -38,4 +38,4 @@ module {
/// Returns the message of an error `e`.
public let message : (e : Error) -> Text = Prim.errorMessage;
-};
+}
diff --git a/src/ExperimentalCycles.mo b/src/ExperimentalCycles.mo
index 320fc15c..9979a9c0 100644
--- a/src/ExperimentalCycles.mo
+++ b/src/ExperimentalCycles.mo
@@ -48,4 +48,4 @@ module {
/// whether or not `refunded` is used to observe them.
public let refunded : () -> (amount : Nat) = Prim.cyclesRefunded;
-};
+}
diff --git a/src/ExperimentalInternetComputer.mo b/src/ExperimentalInternetComputer.mo
index 9d94cd6f..f8eb715f 100644
--- a/src/ExperimentalInternetComputer.mo
+++ b/src/ExperimentalInternetComputer.mo
@@ -29,7 +29,7 @@ module {
let post = Prim.performanceCounter(0);
// performance_counter costs around 200 extra instructions, we perform an empty measurement to decide the overhead
let overhead = pre - init;
- post - pre - overhead;
+ post - pre - overhead
}
-};
+}
diff --git a/src/ExperimentalStableMemory.mo b/src/ExperimentalStableMemory.mo
index e9c6dcf5..d7c2c154 100644
--- a/src/ExperimentalStableMemory.mo
+++ b/src/ExperimentalStableMemory.mo
@@ -95,4 +95,4 @@ module {
/// Traps on out-of-bounds access.
public let storeBlob : (offset : Nat64, value : Blob) -> () = Prim.stableMemoryStoreBlob;
-};
+}
diff --git a/src/Float.mo b/src/Float.mo
index 5f27f923..ebc88e4d 100644
--- a/src/Float.mo
+++ b/src/Float.mo
@@ -81,7 +81,7 @@ module {
case (#exp(prec)) { Prim.floatToFormattedText(x, prec, 1) };
case (#gen(prec)) { Prim.floatToFormattedText(x, prec, 2) };
case (#hex(prec)) { Prim.floatToFormattedText(x, prec, 3) };
- case (#exact) { Prim.floatToFormattedText(x, 17, 2) };
+ case (#exact) { Prim.floatToFormattedText(x, 17, 2) }
};
/// Conversion to Text. Use `format(fmt, x)` for more detailed control.
@@ -119,7 +119,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Float, y : Float) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
/// Returns the negation of `x`, `-x` .
@@ -143,4 +143,4 @@ module {
/// Returns `x` to the power of `y`, `x ** y`.
public func pow(x : Float, y : Float) : Float { x ** y };
-};
+}
diff --git a/src/Func.mo b/src/Func.mo
index 9f8c3007..34cd189d 100644
--- a/src/Func.mo
+++ b/src/Func.mo
@@ -12,8 +12,8 @@ module {
/// ```
public func compose(f : B -> C, g : A -> B) : A -> C {
func(x : A) : C {
- f(g(x));
- };
+ f(g(x))
+ }
};
/// The `identity` function returns its argument.
@@ -33,5 +33,5 @@ module {
/// assert(Func.const(10)("hello") == 10);
/// assert(Func.const(true)(20) == true);
/// ```
- public func const(x : A) : B -> A = func(_) = x;
-};
+ public func const(x : A) : B -> A = func(_) = x
+}
diff --git a/src/Hash.mo b/src/Hash.mo
index 3eee0e03..285c02b6 100644
--- a/src/Hash.mo
+++ b/src/Hash.mo
@@ -14,12 +14,12 @@ module {
/// Project a given bit from the bit vector.
public func bit(h : Hash, pos : Nat) : Bool {
assert (pos <= length);
- (h & (Prim.natToNat32(1) << Prim.natToNat32(pos))) != Prim.natToNat32(0);
+ (h & (Prim.natToNat32(1) << Prim.natToNat32(pos))) != Prim.natToNat32(0)
};
/// Test if two hashes are equal
public func equal(ha : Hash, hb : Hash) : Bool {
- ha == hb;
+ ha == hb
};
/// Computes a hash from the least significant 32-bits of `n`, ignoring other bits.
@@ -30,30 +30,30 @@ module {
j & (255 << 0),
j & (255 << 8),
j & (255 << 16),
- j & (255 << 24),
- ]);
+ j & (255 << 24)
+ ])
};
/// @deprecated This function will be removed in future.
public func debugPrintBits(bits : Hash) {
for (j in Iter.range(0, length - 1)) {
if (bit(bits, j)) {
- Prim.debugPrint("1");
+ Prim.debugPrint("1")
} else {
- Prim.debugPrint("0");
- };
- };
+ Prim.debugPrint("0")
+ }
+ }
};
/// @deprecated This function will be removed in future.
public func debugPrintBitsRev(bits : Hash) {
for (j in Iter.revRange(length - 1, 0)) {
if (bit(bits, Prim.abs(j))) {
- Prim.debugPrint("1");
+ Prim.debugPrint("1")
} else {
- Prim.debugPrint("0");
- };
- };
+ Prim.debugPrint("0")
+ }
+ }
};
/// Jenkin's one at a time:
@@ -71,12 +71,12 @@ module {
for (natOfKey in key.vals()) {
hash := hash +% natOfKey;
hash := hash +% hash << 10;
- hash := hash ^ (hash >> 6);
+ hash := hash ^ (hash >> 6)
};
hash := hash +% hash << 3;
hash := hash ^ (hash >> 11);
hash := hash +% hash << 15;
- return hash;
+ return hash
};
-};
+}
diff --git a/src/HashMap.mo b/src/HashMap.mo
index 382c5d1f..77fe95c5 100644
--- a/src/HashMap.mo
+++ b/src/HashMap.mo
@@ -32,7 +32,7 @@ module {
public class HashMap(
initCapacity : Nat,
keyEq : (K, K) -> Bool,
- keyHash : K -> Hash.Hash,
+ keyHash : K -> Hash.Hash
) {
var table : [var KVs] = [var];
@@ -48,7 +48,7 @@ module {
func keyHash_(k : K) : Key = (keyHash(k), k);
func keyHashEq(k1 : Key, k2 : Key) : Bool {
- k1.0 == k2.0 and keyEq(k1.1, k2.1);
+ k1.0 == k2.0 and keyEq(k1.1, k2.1)
};
/// Removes the entry with the key `k` and returns the associated value if it
@@ -62,12 +62,12 @@ module {
table[pos] := kvs2;
switch (ov) {
case null {};
- case _ { _count -= 1 };
+ case _ { _count -= 1 }
};
- ov;
+ ov
} else {
- null;
- };
+ null
+ }
};
/// Gets the entry with the key `k` and returns its associated value if it
@@ -76,10 +76,10 @@ module {
let h = Prim.nat32ToNat(keyHash(k));
let m = table.size();
let v = if (m > 0) {
- AssocList.find, V>(table[h % m], keyHash_(k), keyHashEq);
+ AssocList.find, V>(table[h % m], keyHash_(k), keyHashEq)
} else {
- null;
- };
+ null
+ }
};
/// Insert the value `v` at key `k`. Overwrites an existing entry with key `k`
@@ -91,12 +91,12 @@ module {
if (_count >= table.size()) {
let size = if (_count == 0) {
if (initCapacity > 0) {
- initCapacity;
+ initCapacity
} else {
- 1;
- };
+ 1
+ }
} else {
- table.size() * 2;
+ table.size() * 2
};
let table2 = A.init>(size, null);
for (i in table.keys()) {
@@ -107,12 +107,12 @@ module {
case (?((k, v), kvsTail)) {
let pos2 = Nat32.toNat(k.0) % table2.size(); // critical: uses saved hash. no re-hash.
table2[pos2] := ?((k, v), table2[pos2]);
- kvs := kvsTail;
- };
- };
- };
+ kvs := kvsTail
+ }
+ }
+ }
};
- table := table2;
+ table := table2
};
let h = Prim.nat32ToNat(keyHash(k));
let pos = h % table.size();
@@ -120,26 +120,26 @@ module {
table[pos] := kvs2;
switch (ov) {
case null { _count += 1 };
- case _ {};
+ case _ {}
};
- ov;
+ ov
};
/// An `Iter` over the keys.
public func keys() : Iter.Iter {
- Iter.map(entries(), func(kv : (K, V)) : K { kv.0 });
+ Iter.map(entries(), func(kv : (K, V)) : K { kv.0 })
};
/// An `Iter` over the values.
public func vals() : Iter.Iter {
- Iter.map(entries(), func(kv : (K, V)) : V { kv.1 });
+ Iter.map(entries(), func(kv : (K, V)) : V { kv.1 })
};
/// Returns an iterator over the key value pairs in this
/// `HashMap`. Does _not_ modify the `HashMap`.
public func entries() : Iter.Iter<(K, V)> {
if (table.size() == 0) {
- object { public func next() : ?(K, V) { null } };
+ object { public func next() : ?(K, V) { null } }
} else {
object {
var kvs = table[0];
@@ -148,21 +148,21 @@ module {
switch kvs {
case (?(kv, kvs2)) {
kvs := kvs2;
- ?(kv.0.1, kv.1);
+ ?(kv.0.1, kv.1)
};
case null {
if (nextTablePos < table.size()) {
kvs := table[nextTablePos];
nextTablePos += 1;
- next();
+ next()
} else {
- null;
- };
- };
- };
- };
- };
- };
+ null
+ }
+ }
+ }
+ }
+ }
+ }
};
};
@@ -172,13 +172,13 @@ module {
public func clone(
h : HashMap,
keyEq : (K, K) -> Bool,
- keyHash : K -> Hash.Hash,
+ keyHash : K -> Hash.Hash
) : HashMap {
let h2 = HashMap(h.size(), keyEq, keyHash);
for ((k, v) in h.entries()) {
- h2.put(k, v);
+ h2.put(k, v)
};
- h2;
+ h2
};
/// Clone from any iterator of key-value pairs
@@ -186,45 +186,45 @@ module {
iter : Iter.Iter<(K, V)>,
initCapacity : Nat,
keyEq : (K, K) -> Bool,
- keyHash : K -> Hash.Hash,
+ keyHash : K -> Hash.Hash
) : HashMap {
let h = HashMap(initCapacity, keyEq, keyHash);
for ((k, v) in iter) {
- h.put(k, v);
+ h.put(k, v)
};
- h;
+ h
};
public func map(
h : HashMap,
keyEq : (K, K) -> Bool,
keyHash : K -> Hash.Hash,
- mapFn : (K, V1) -> V2,
+ mapFn : (K, V1) -> V2
) : HashMap {
let h2 = HashMap(h.size(), keyEq, keyHash);
for ((k, v1) in h.entries()) {
let v2 = mapFn(k, v1);
- h2.put(k, v2);
+ h2.put(k, v2)
};
- h2;
+ h2
};
public func mapFilter(
h : HashMap,
keyEq : (K, K) -> Bool,
keyHash : K -> Hash.Hash,
- mapFn : (K, V1) -> ?V2,
+ mapFn : (K, V1) -> ?V2
) : HashMap {
let h2 = HashMap(h.size(), keyEq, keyHash);
for ((k, v1) in h.entries()) {
switch (mapFn(k, v1)) {
case null {};
case (?v2) {
- h2.put(k, v2);
- };
- };
+ h2.put(k, v2)
+ }
+ }
};
- h2;
+ h2
};
-};
+}
diff --git a/src/Heap.mo b/src/Heap.mo
index f468c2d9..d779ca3c 100644
--- a/src/Heap.mo
+++ b/src/Heap.mo
@@ -16,33 +16,33 @@ module {
/// Get purely-functional representation
public func share() : Tree {
- heap;
+ heap
};
/// Put purely-functional representation into class. Need to make sure the tree is constructed with the same compare function
public func unsafeUnshare(t : Tree) {
- heap := t;
+ heap := t
};
/// Insert an element to the heap
public func put(x : T) {
- heap := merge(heap, ?(1, x, null, null), ord);
+ heap := merge(heap, ?(1, x, null, null), ord)
};
/// Return the minimal element
public func peekMin() : ?T {
switch heap {
case (null) { null };
- case (?(_, x, _, _)) { ?x };
- };
+ case (?(_, x, _, _)) { ?x }
+ }
};
/// Delete the minimal element
public func deleteMin() {
switch heap {
case null {};
- case (?(_, _, a, b)) { heap := merge(a, b, ord) };
- };
+ case (?(_, _, a, b)) { heap := merge(a, b, ord) }
+ }
};
/// Remove the minimal element and return its value
@@ -51,25 +51,25 @@ module {
case null { null };
case (?(_, x, a, b)) {
heap := merge(a, b, ord);
- ?x;
- };
- };
- };
+ ?x
+ }
+ }
+ }
};
func rank(heap : Tree) : Int {
switch heap {
case null { 0 };
- case (?(r, _, _, _)) { r };
- };
+ case (?(r, _, _, _)) { r }
+ }
};
func makeT(x : T, a : Tree, b : Tree) : Tree {
if (rank(a) >= rank(b)) {
- ?(rank(b) + 1, x, a, b);
+ ?(rank(b) + 1, x, a, b)
} else {
- ?(rank(a) + 1, x, b, a);
- };
+ ?(rank(a) + 1, x, b, a)
+ }
};
func merge(h1 : Tree, h2 : Tree, ord : (T, T) -> O.Order) : Tree {
@@ -79,10 +79,10 @@ module {
case (?(_, x, a, b), ?(_, y, c, d)) {
switch (ord(x, y)) {
case (#less) { makeT(x, a, merge(b, h2, ord)) };
- case _ { makeT(y, c, merge(d, h1, ord)) };
- };
- };
- };
+ case _ { makeT(y, c, merge(d, h1, ord)) }
+ }
+ }
+ }
};
/// Convert iterator into a heap in O(N) time.
@@ -93,21 +93,21 @@ module {
switch (xs) {
case (null) { null };
case (?(hd, null)) { ?(hd, null) };
- case (?(h1, ?(h2, tl))) { ?(merge(h1, h2, ord), join(tl)) };
- };
+ case (?(h1, ?(h2, tl))) { ?(merge(h1, h2, ord), join(tl)) }
+ }
};
switch (xs) {
case null { P.unreachable() };
case (?(hd, null)) { hd };
- case _ { build(join(xs)) };
- };
+ case _ { build(join(xs)) }
+ }
};
let list = I.toList(I.map(iter, func(x : T) : Tree { ?(1, x, null, null) }));
if (not L.isNil(list)) {
let t = build(list);
- heap.unsafeUnshare(t);
+ heap.unsafeUnshare(t)
};
- heap;
+ heap
};
-};
+}
diff --git a/src/Int.mo b/src/Int.mo
index f1f5c000..35c6fab4 100644
--- a/src/Int.mo
+++ b/src/Int.mo
@@ -18,7 +18,7 @@ module {
/// Conversion.
public let toText : Int -> Text = func(x) {
if (x == 0) {
- return "0";
+ return "0"
};
let isNegative = x < 0;
@@ -41,23 +41,23 @@ module {
case 7 { "7" };
case 8 { "8" };
case 9 { "9" };
- case _ { Prelude.unreachable() };
- },
+ case _ { Prelude.unreachable() }
+ }
) # text;
- int := int / base;
+ int := int / base
};
- return if isNegative { "-" # text } else { text };
+ return if isNegative { "-" # text } else { text }
};
/// Returns the minimum of `x` and `y`.
public func min(x : Int, y : Int) : Int {
- if (x < y) { x } else { y };
+ if (x < y) { x } else { y }
};
/// Returns the maximum of `x` and `y`.
public func max(x : Int, y : Int) : Int {
- if (x < y) { y } else { x };
+ if (x < y) { y } else { x }
};
// this is a local copy of deprecated Hash.hashNat8 (redefined to suppress the warning)
@@ -66,12 +66,12 @@ module {
for (natOfKey in key.vals()) {
hash := hash +% natOfKey;
hash := hash +% hash << 10;
- hash := hash ^ (hash >> 6);
+ hash := hash ^ (hash >> 6)
};
hash := hash +% hash << 3;
hash := hash ^ (hash >> 11);
hash := hash +% hash << 15;
- return hash;
+ return hash
};
/// Computes a hash from the least significant 32-bits of `i`, ignoring other bits.
@@ -83,8 +83,8 @@ module {
j & (255 << 0),
j & (255 << 8),
j & (255 << 16),
- j & (255 << 24),
- ]);
+ j & (255 << 24)
+ ])
};
/// @deprecated This function will be removed in future.
@@ -96,8 +96,8 @@ module {
j & (255 << 0),
j & (255 << 8),
j & (255 << 16),
- j & (255 << 24),
- ]);
+ j & (255 << 24)
+ ])
};
/// Returns `x == y`.
@@ -120,7 +120,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Int, y : Int) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
/// Returns the negation of `x`, `-x` .
@@ -146,4 +146,4 @@ module {
/// Returns `x` to the power of `y`, `x ** y`.
public func pow(x : Int, y : Int) : Int { x ** y };
-};
+}
diff --git a/src/Int16.mo b/src/Int16.mo
index b32de6c5..dfc8b176 100644
--- a/src/Int16.mo
+++ b/src/Int16.mo
@@ -26,22 +26,22 @@ module {
/// Returns the Text representation of `x`.
public func toText(x : Int16) : Text {
- Int.toText(toInt(x));
+ Int.toText(toInt(x))
};
/// Returns the absolute value of `x`. Traps when `x = -2^15`.
public func abs(x : Int16) : Int16 {
- fromInt(Int.abs(toInt(x)));
+ fromInt(Int.abs(toInt(x)))
};
/// Returns the minimum of `x` and `y`.
public func min(x : Int16, y : Int16) : Int16 {
- if (x < y) { x } else { y };
+ if (x < y) { x } else { y }
};
/// Returns the maximum of `x` and `y`.
public func max(x : Int16, y : Int16) : Int16 {
- if (x < y) { y } else { x };
+ if (x < y) { y } else { x }
};
/// Returns `x == y`.
@@ -64,7 +64,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Int16, y : Int16) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
/// Returns the negation of `x`, `-x`. Traps on overflow.
@@ -116,22 +116,22 @@ module {
/// Returns the value of bit `p mod 16` in `x`, `(x & 2^(p mod 16)) == 2^(p mod 16)`.
public func bittest(x : Int16, p : Nat) : Bool {
- Prim.btstInt16(x, Prim.intToInt16(p));
+ Prim.btstInt16(x, Prim.intToInt16(p))
};
/// Returns the value of setting bit `p mod 16` in `x` to `1`.
public func bitset(x : Int16, p : Nat) : Int16 {
- x | (1 << Prim.intToInt16(p));
+ x | (1 << Prim.intToInt16(p))
};
/// Returns the value of clearing bit `p mod 16` in `x` to `0`.
public func bitclear(x : Int16, p : Nat) : Int16 {
- x & ^(1 << Prim.intToInt16(p));
+ x & ^(1 << Prim.intToInt16(p))
};
/// Returns the value of flipping bit `p mod 16` in `x`.
public func bitflip(x : Int16, p : Nat) : Int16 {
- x ^ (1 << Prim.intToInt16(p));
+ x ^ (1 << Prim.intToInt16(p))
};
/// Returns the count of non-zero bits in `x`.
@@ -153,5 +153,5 @@ module {
public func mulWrap(x : Int16, y : Int16) : Int16 { x *% y };
/// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`.
- public func powWrap(x : Int16, y : Int16) : Int16 { x **% y };
-};
+ public func powWrap(x : Int16, y : Int16) : Int16 { x **% y }
+}
diff --git a/src/Int32.mo b/src/Int32.mo
index d2aac647..7f5bd4f3 100644
--- a/src/Int32.mo
+++ b/src/Int32.mo
@@ -26,22 +26,22 @@ module {
/// Returns the Text representation of `x`.
public func toText(x : Int32) : Text {
- Int.toText(toInt(x));
+ Int.toText(toInt(x))
};
/// Returns the absolute value of `x`. Traps when `x = -2^31`.
public func abs(x : Int32) : Int32 {
- fromInt(Int.abs(toInt(x)));
+ fromInt(Int.abs(toInt(x)))
};
/// Returns the minimum of `x` and `y`.
public func min(x : Int32, y : Int32) : Int32 {
- if (x < y) { x } else { y };
+ if (x < y) { x } else { y }
};
/// Returns the maximum of `x` and `y`.
public func max(x : Int32, y : Int32) : Int32 {
- if (x < y) { y } else { x };
+ if (x < y) { y } else { x }
};
/// Returns `x == y`.
@@ -64,7 +64,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Int32, y : Int32) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
/// Returns the negation of `x`, `-x`. Traps on overflow.
@@ -116,22 +116,22 @@ module {
/// Returns the value of bit `p mod 16` in `x`, `(x & 2^(p mod 16)) == 2^(p mod 16)`.
public func bittest(x : Int32, p : Nat) : Bool {
- Prim.btstInt32(x, Prim.intToInt32(p));
+ Prim.btstInt32(x, Prim.intToInt32(p))
};
/// Returns the value of setting bit `p mod 16` in `x` to `1`.
public func bitset(x : Int32, p : Nat) : Int32 {
- x | (1 << Prim.intToInt32(p));
+ x | (1 << Prim.intToInt32(p))
};
/// Returns the value of clearing bit `p mod 16` in `x` to `0`.
public func bitclear(x : Int32, p : Nat) : Int32 {
- x & ^(1 << Prim.intToInt32(p));
+ x & ^(1 << Prim.intToInt32(p))
};
/// Returns the value of flipping bit `p mod 16` in `x`.
public func bitflip(x : Int32, p : Nat) : Int32 {
- x ^ (1 << Prim.intToInt32(p));
+ x ^ (1 << Prim.intToInt32(p))
};
/// Returns the count of non-zero bits in `x`.
@@ -155,4 +155,4 @@ module {
/// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`.
public func powWrap(x : Int32, y : Int32) : Int32 { x **% y };
-};
+}
diff --git a/src/Int64.mo b/src/Int64.mo
index 89c3f719..d4739abe 100644
--- a/src/Int64.mo
+++ b/src/Int64.mo
@@ -26,22 +26,22 @@ module {
/// Returns the Text representation of `x`.
public func toText(x : Int64) : Text {
- Int.toText(toInt(x));
+ Int.toText(toInt(x))
};
/// Returns the absolute value of `x`. Traps when `x = -2^63`.
public func abs(x : Int64) : Int64 {
- fromInt(Int.abs(toInt(x)));
+ fromInt(Int.abs(toInt(x)))
};
/// Returns the minimum of `x` and `y`.
public func min(x : Int64, y : Int64) : Int64 {
- if (x < y) { x } else { y };
+ if (x < y) { x } else { y }
};
/// Returns the maximum of `x` and `y`.
public func max(x : Int64, y : Int64) : Int64 {
- if (x < y) { y } else { x };
+ if (x < y) { y } else { x }
};
/// Returns `x == y`.
@@ -64,7 +64,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Int64, y : Int64) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
/// Returns the negation of `x`, `-x`. Traps on overflow.
@@ -116,22 +116,22 @@ module {
/// Returns the value of bit `p mod 64` in `x`, `(x & 2^(p mod 64)) == 2^(p mod 64)`.
public func bittest(x : Int64, p : Nat) : Bool {
- Prim.btstInt64(x, Prim.intToInt64(p));
+ Prim.btstInt64(x, Prim.intToInt64(p))
};
/// Returns the value of setting bit `p mod 64` in `x` to `1`.
public func bitset(x : Int64, p : Nat) : Int64 {
- x | (1 << Prim.intToInt64(p));
+ x | (1 << Prim.intToInt64(p))
};
/// Returns the value of clearing bit `p mod 64` in `x` to `0`.
public func bitclear(x : Int64, p : Nat) : Int64 {
- x & ^(1 << Prim.intToInt64(p));
+ x & ^(1 << Prim.intToInt64(p))
};
/// Returns the value of flipping bit `p mod 64` in `x`.
public func bitflip(x : Int64, p : Nat) : Int64 {
- x ^ (1 << Prim.intToInt64(p));
+ x ^ (1 << Prim.intToInt64(p))
};
/// Returns the count of non-zero bits in `x`.
@@ -155,4 +155,4 @@ module {
/// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`.
public func powWrap(x : Int64, y : Int64) : Int64 { x **% y };
-};
+}
diff --git a/src/Int8.mo b/src/Int8.mo
index d02a947c..a2e81f5b 100644
--- a/src/Int8.mo
+++ b/src/Int8.mo
@@ -26,22 +26,22 @@ module {
/// Returns the Text representation of `x`.
public func toText(x : Int8) : Text {
- Int.toText(toInt(x));
+ Int.toText(toInt(x))
};
/// Returns the absolute value of `x`. Traps when `x = -2^7`.
public func abs(x : Int8) : Int8 {
- fromInt(Int.abs(toInt(x)));
+ fromInt(Int.abs(toInt(x)))
};
/// Returns the minimum of `x` and `y`.
public func min(x : Int8, y : Int8) : Int8 {
- if (x < y) { x } else { y };
+ if (x < y) { x } else { y }
};
/// Returns the maximum of `x` and `y`.
public func max(x : Int8, y : Int8) : Int8 {
- if (x < y) { y } else { x };
+ if (x < y) { y } else { x }
};
/// Returns `x == y`.
@@ -64,7 +64,7 @@ module {
/// Returns the order of `x` and `y`.
public func compare(x : Int8, y : Int8) : { #less; #equal; #greater } {
- if (x < y) { #less } else if (x == y) { #equal } else { #greater };
+ if (x < y) { #less } else if (x == y) { #equal } else { #greater }
};
/// Returns the negation of `x`, `-x`. Traps on overflow.
@@ -116,22 +116,22 @@ module {
/// Returns the value of bit `p mod 8` in `x`, `(x & 2^(p mod 8)) == 2^(p mod 8)`.
public func bittest(x : Int8, p : Nat) : Bool {
- Prim.btstInt8(x, Prim.intToInt8(p));
+ Prim.btstInt8(x, Prim.intToInt8(p))
};
/// Returns the value of setting bit `p mod 8` in `x` to `1`.
public func bitset(x : Int8, p : Nat) : Int8 {
- x | (1 << Prim.intToInt8(p));
+ x | (1 << Prim.intToInt8(p))
};
/// Returns the value of clearing bit `p mod 8` in `x` to `0`.
public func bitclear(x : Int8, p : Nat) : Int8 {
- x & ^(1 << Prim.intToInt8(p));
+ x & ^(1 << Prim.intToInt8(p))
};
/// Returns the value of flipping bit `p mod 8` in `x`.
public func bitflip(x : Int8, p : Nat) : Int8 {
- x ^ (1 << Prim.intToInt8(p));
+ x ^ (1 << Prim.intToInt8(p))
};
/// Returns the count of non-zero bits in `x`.
@@ -155,4 +155,4 @@ module {
/// Returns `x` to the power of `y`, `x **% y`. Wraps on overflow. Traps if `y < 0`.
public func powWrap(x : Int8, y : Int8) : Int8 { x **% y };
-};
+}
diff --git a/src/Iter.mo b/src/Iter.mo
index ecc7969a..2d18c9b3 100644
--- a/src/Iter.mo
+++ b/src/Iter.mo
@@ -35,8 +35,8 @@ module {
public class range(x : Nat, y : Int) {
var i = x;
public func next() : ?Nat {
- if (i > y) { null } else { let j = i; i += 1; ?j };
- };
+ if (i > y) { null } else { let j = i; i += 1; ?j }
+ }
};
/// Like `range` but produces the values in the opposite
@@ -44,8 +44,8 @@ module {
public class revRange(x : Int, y : Int) {
var i = x;
public func next() : ?Int {
- if (i < y) { null } else { let j = i; i -= 1; ?j };
- };
+ if (i < y) { null } else { let j = i; i -= 1; ?j }
+ }
};
/// Calls a function `f` on every value produced by an iterator and discards
@@ -61,21 +61,21 @@ module {
/// ```
public func iterate(
xs : Iter,
- f : (A, Nat) -> (),
+ f : (A, Nat) -> ()
) {
var i = 0;
label l loop {
switch (xs.next()) {
case (?next) {
- f(next, i);
+ f(next, i)
};
case (null) {
- break l;
- };
+ break l
+ }
};
i += 1;
- continue l;
- };
+ continue l
+ }
};
/// Consumes an iterator and counts how many elements were produced
@@ -83,7 +83,7 @@ module {
public func size(xs : Iter) : Nat {
var len = 0;
iterate(xs, func(x, i) { len += 1 });
- len;
+ len
};
/// Takes a function and an iterator and returns a new iterator that lazily applies
@@ -101,13 +101,13 @@ module {
public func next() : ?B {
switch (xs.next()) {
case (?next) {
- ?f(next);
+ ?f(next)
};
case (null) {
- null;
- };
- };
- };
+ null
+ }
+ }
+ }
};
/// Takes a function and an iterator and returns a new iterator that produces
@@ -125,17 +125,17 @@ module {
loop {
switch (xs.next()) {
case (null) {
- return null;
+ return null
};
case (?x) {
if (f(x)) {
- return ?x;
- };
- };
- };
+ return ?x
+ }
+ }
+ }
};
- null;
- };
+ null
+ }
};
/// Creates an iterator that produces an infinite sequence of `x`.
@@ -149,8 +149,8 @@ module {
/// ```
public func make(x : A) : Iter = object {
public func next() : ?A {
- ?x;
- };
+ ?x
+ }
};
/// Creates an iterator that produces the elements of an Array in ascending index order.
@@ -168,21 +168,21 @@ module {
object {
public func next() : ?A {
if (ix >= size) {
- return null;
+ return null
} else {
let res = ?(xs[ix]);
ix += 1;
- return res;
- };
- };
- };
+ return res
+ }
+ }
+ }
};
/// Like `fromArray` but for Arrays with mutable elements. Captures
/// the elements of the Array at the time the iterator is created, so
/// further modifications won't be reflected in the iterator.
public func fromArrayMut(xs : [var A]) : Iter {
- fromArray(Array.freeze(xs));
+ fromArray(Array.freeze(xs))
};
/// Like `fromArray` but for Lists.
@@ -197,12 +197,12 @@ module {
public func toArray(xs : Iter) : [A] {
let buffer = Buffer.Buffer(8);
iterate(xs, func(x : A, ix : Nat) { buffer.add(x) });
- return Buffer.toArray(buffer);
+ return Buffer.toArray(buffer)
};
/// Like `toArray` but for Arrays with mutable elements.
public func toArrayMut(xs : Iter) : [var A] {
- Array.thaw(toArray(xs));
+ Array.thaw(toArray(xs))
};
/// Like `toArray` but for Lists.
@@ -211,17 +211,17 @@ module {
iterate(
xs,
func(x, _i) {
- result := List.push(x, result);
- },
+ result := List.push(x, result)
+ }
);
- List.reverse(result);
+ List.reverse(result)
};
/// Sorted iterator. Will iterate over *all* elements to sort them, necessarily.
public func sort(xs : Iter, compare : (A, A) -> Order.Order) : Iter {
let a = toArrayMut(xs);
Array.sortInPlace(a, compare);
- fromArrayMut(a);
+ fromArrayMut(a)
};
-};
+}
diff --git a/src/IterType.mo b/src/IterType.mo
index 238ee399..1c258ff4 100644
--- a/src/IterType.mo
+++ b/src/IterType.mo
@@ -3,5 +3,5 @@
// Just here to break cyclic module definitions
module {
- public type Iter = { next : () -> ?T };
-};
+ public type Iter = { next : () -> ?T }
+}
diff --git a/src/List.mo b/src/List.mo
index a6cf56a5..9323e3f4 100644
--- a/src/List.mo
+++ b/src/List.mo
@@ -20,8 +20,8 @@ module {
public func isNil(l : List) : Bool {
switch l {
case null { true };
- case _ { false };
- };
+ case _ { false }
+ }
};
/// Construct a list by pre-pending a value.
@@ -33,8 +33,8 @@ module {
switch l {
case null { null };
case (?(x, null)) { ?x };
- case (?(_, t)) { last(t) };
- };
+ case (?(_, t)) { last(t) }
+ }
};
/// Treat the list as a stack.
@@ -42,8 +42,8 @@ module {
public func pop(l : List) : (?T, List) {
switch l {
case null { (null, null) };
- case (?(h, t)) { (?h, t) };
- };
+ case (?(h, t)) { (?h, t) }
+ }
};
/// Return the length of the list.
@@ -51,10 +51,10 @@ module {
func rec(l : List, n : Nat) : Nat {
switch l {
case null { n };
- case (?(_, t)) { rec(t, n + 1) };
- };
+ case (?(_, t)) { rec(t, n + 1) }
+ }
};
- rec(l, 0);
+ rec(l, 0)
};
/// Access any item in a list, zero-based.
///
@@ -65,8 +65,8 @@ module {
switch (n, l) {
case (_, null) { null };
case (0, (?(h, t))) { ?h };
- case (_, (?(_, t))) { get(t, n - 1) };
- };
+ case (_, (?(_, t))) { get(t, n - 1) }
+ }
};
/// Reverses the list
@@ -74,10 +74,10 @@ module {
func rec(l : List, r : List) : List {
switch l {
case null { r };
- case (?(h, t)) { rec(t, ?(h, r)) };
- };
+ case (?(h, t)) { rec(t, ?(h, r)) }
+ }
};
- rec(l, null);
+ rec(l, null)
};
/// Call the given function with each list element in turn.
@@ -87,8 +87,8 @@ module {
public func iterate(l : List, f : T -> ()) {
switch l {
case null { () };
- case (?(h, t)) { f(h); iterate(t, f) };
- };
+ case (?(h, t)) { f(h); iterate(t, f) }
+ }
};
/// Call the given function on each list element and collect the results
@@ -96,8 +96,8 @@ module {
public func map(l : List, f : T -> S) : List {
switch l {
case null { null };
- case (?(h, t)) { ?(f(h), map(t, f)) };
- };
+ case (?(h, t)) { ?(f(h), map(t, f)) }
+ }
};
/// Create a new list with only those elements of the original list for which
@@ -107,12 +107,12 @@ module {
case null { null };
case (?(h, t)) {
if (f(h)) {
- ?(h, filter(t, f));
+ ?(h, filter(t, f))
} else {
- filter(t, f);
- };
- };
- };
+ filter(t, f)
+ }
+ }
+ }
};
/// Create two new lists from the results of a given function (`f`).
@@ -126,13 +126,13 @@ module {
if (f(h)) {
// call f in-order
let (l, r) = partition(t, f);
- (?(h, l), r);
+ (?(h, l), r)
} else {
let (l, r) = partition(t, f);
- (l, ?(h, r));
- };
- };
- };
+ (l, ?(h, r))
+ }
+ }
+ }
};
/// Call the given function on each list element, and collect the non-null results
@@ -143,10 +143,10 @@ module {
case (?(h, t)) {
switch (f(h)) {
case null { mapFilter(t, f) };
- case (?h_) { ?(h_, mapFilter(t, f)) };
- };
- };
- };
+ case (?h_) { ?(h_, mapFilter(t, f)) }
+ }
+ }
+ }
};
/// Maps a Result-returning function over a List and returns either
@@ -158,32 +158,32 @@ module {
case (?(head, tail)) {
switch (f(head)) {
case (#err(err)) { #err(err) };
- case (#ok(ok)) { go(tail, ?(ok, acc)) };
- };
- };
- };
+ case (#ok(ok)) { go(tail, ?(ok, acc)) }
+ }
+ }
+ }
};
- Result.mapOk(go(xs, null), func(xs : List) : List = reverse(xs));
+ Result.mapOk(go(xs, null), func(xs : List) : List = reverse(xs))
};
/// Append the elements from the reverse of one list to another list.
func revAppend(l : List, m : List) : List {
switch l {
case null { m };
- case (?(h, t)) { revAppend(t, ?(h, m)) };
- };
+ case (?(h, t)) { revAppend(t, ?(h, m)) }
+ }
};
/// Append the elements from one list to another list.
public func append(l : List, m : List) : List {
- revAppend(reverse(l), m);
+ revAppend(reverse(l), m)
};
/// Concatenate a list of lists.
///
/// In some languages, this operation is also known as a `list join`.
public func flatten(l : List>) : List {
- foldLeft, List>(l, null, func(a, b) { append(a, b) });
+ foldLeft, List>(l, null, func(a, b) { append(a, b) })
};
/// Returns the first `n` elements of the given list.
@@ -193,8 +193,8 @@ module {
switch (l, n) {
case (_, 0) { null };
case (null, _) { null };
- case (?(h, t), m) { ?(h, take(t, m - 1)) };
- };
+ case (?(h, t), m) { ?(h, take(t, m - 1)) }
+ }
};
/// Drop the first `n` elements from the given list.
@@ -202,24 +202,24 @@ module {
switch (l, n) {
case (l_, 0) { l_ };
case (null, _) { null };
- case ((?(h, t)), m) { drop(t, m - 1) };
- };
+ case ((?(h, t)), m) { drop(t, m - 1) }
+ }
};
/// Fold the list left-to-right using the given function (`f`).
public func foldLeft(l : List, a : S, f : (S, T) -> S) : S {
switch l {
case null { a };
- case (?(h, t)) { foldLeft(t, f(a, h), f) };
- };
+ case (?(h, t)) { foldLeft(t, f(a, h), f) }
+ }
};
/// Fold the list right-to-left using the given function (`f`).
public func foldRight(l : List, a : S, f : (T, S) -> S) : S {
switch l {
case null { a };
- case (?(h, t)) { f(h, foldRight(t, a, f)) };
- };
+ case (?(h, t)) { f(h, foldRight(t, a, f)) }
+ }
};
/// Return the first element for which the given predicate `f` is true,
@@ -227,8 +227,8 @@ module {
public func find(l : List