arr.data[idx] = value;
}
-// Uses '==' to compare for equality.
-contains :: (arr: [] $T, x: T) -> bool {
- for it: arr do if it == x do return true;
- return false;
+contains :: #match {
+ // Uses '==' to compare for equality.
+ (arr: [] $T, x: T) -> bool {
+ for it: arr do if it == x do return true;
+ return false;
+ },
+
+ macro (arr: [] $T, $cmp: Code) -> bool {
+ for it: arr do if #insert cmp do return true;
+ return false;
+ }
}
// Uses '+' to sum.
return sum / cast(T) arr.count;
}
+reverse :: (arr: [] $T) {
+ for i: arr.count / 2 {
+ arr[i], arr[arr.count - 1 - i] = arr[arr.count - 1 - i], arr[i];
+ }
+}
+
//
// Simple insertion sort
// cmp should return >0 if left > right