// Generated by ReScript, PLEASE EDIT WITH CARE import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function reverse_range(a, i, len) { if (len === 0) { return; } for (let k = 0, k_finish = (len - 1 | 0) / 2 | 0; k <= k_finish; ++k) { let t = a[i + k | 0]; a[i + k | 0] = a[((i + len | 0) - 1 | 0) - k | 0]; a[((i + len | 0) - 1 | 0) - k | 0] = t; } } function reverse_in_place(a) { reverse_range(a, 0, a.length); } function reverse(a) { let b_len = a.length; if (b_len === 0) { return []; } let b = a.slice(); for (let i = 0; i < b_len; ++i) { b[i] = a[(b_len - 1 | 0) - i | 0]; } return b; } function reverse_of_list(x) { if (x === 0) { return []; } let len = Stdlib_List.length(x); let a = Stdlib_Array.make(len, x.hd); let _i = 0; let _x = x.tl; while (true) { let x$1 = _x; let i = _i; if (x$1 === 0) { return a; } a[(len - i | 0) - 2 | 0] = x$1.hd; _i = i + 1 | 0; _x = x$1.tl; continue; }; } function filter(f, a) { let arr_len = a.length; let _acc = /* [] */0; let _i = 0; while (true) { let i = _i; let acc = _acc; if (i === arr_len) { return reverse_of_list(acc); } let v = a[i]; if (f(v)) { _acc = {hd: v, tl: acc}; _i = i + 1 | 0; continue; } _i = i + 1 | 0; continue; }; } function filter_map(f, a) { let arr_len = a.length; let _acc = /* [] */0; let _i = 0; while (true) { let i = _i; let acc = _acc; if (i === arr_len) { return reverse_of_list(acc); } let v = a[i]; let v$1 = f(v); if (v$1 !== undefined) { _acc = {hd: Primitive_option.valFromOption(v$1), tl: acc}; _i = i + 1 | 0; continue; } _i = i + 1 | 0; continue; }; } function range(from, to_) { if (from > to_) { throw { RE_EXN_ID: "Invalid_argument", _1: "Ext_array_test.range", Error: new Error() }; } return Stdlib_Array.fromInitializer((to_ - from | 0) + 1 | 0, i => i + from | 0); } function map2i(f, a, b) { let len = a.length; if (len !== b.length) { throw { RE_EXN_ID: "Invalid_argument", _1: "Ext_array_test.map2i", Error: new Error() }; } return a.map((i, a) => f(i, a, b[i])); } function tolist_aux(a, f, _i, _res) { while (true) { let res = _res; let i = _i; if (i < 0) { return res; } let v = a[i]; let v$1 = f(v); _i = i - 1 | 0; _res = v$1 !== undefined ? ({hd: Primitive_option.valFromOption(v$1), tl: res}) : res; continue; }; } function to_list_map(f, a) { return tolist_aux(a, f, a.length - 1 | 0, /* [] */0); } function to_list_map_acc(f, a, acc) { return tolist_aux(a, f, a.length - 1 | 0, acc); } function of_list_map(f, a) { if (a === 0) { return []; } let tl = a.tl; let hd = f(a.hd); let len = Stdlib_List.length(tl) + 1 | 0; let arr = Stdlib_Array.make(len, hd); let _i = 1; let _x = tl; while (true) { let x = _x; let i = _i; if (x === 0) { return arr; } arr[i] = f(x.hd); _i = i + 1 | 0; _x = x.tl; continue; }; } function rfind_with_index(arr, cmp, v) { let len = arr.length; let _i = len - 1 | 0; while (true) { let i = _i; if (i < 0) { return i; } if (cmp(arr[i], v)) { return i; } _i = i - 1 | 0; continue; }; } function rfind_and_split(arr, cmp, v) { let i = rfind_with_index(arr, cmp, v); if (i < 0) { return "No_split"; } else { return { NAME: "Split", VAL: [ arr.slice(0, i), arr.slice(i + 1 | 0) ] }; } } function find_with_index(arr, cmp, v) { let len = arr.length; let _i = 0; while (true) { let i = _i; if (i >= len) { return -1; } if (cmp(arr[i], v)) { return i; } _i = i + 1 | 0; continue; }; } function find_and_split(arr, cmp, v) { let i = find_with_index(arr, cmp, v); if (i < 0) { return "No_split"; } else { return { NAME: "Split", VAL: [ arr.slice(0, i), arr.slice(i + 1 | 0) ] }; } } function exists(p, a) { let n = a.length; let _i = 0; while (true) { let i = _i; if (i === n) { return false; } if (p(a[i])) { return true; } _i = i + 1 | 0; continue; }; } function is_empty(arr) { return arr.length === 0; } function unsafe_loop(_index, len, p, xs, ys) { while (true) { let index = _index; if (index >= len) { return true; } if (!p(xs[index], ys[index])) { return false; } _index = index + 1 | 0; continue; }; } function for_all2_no_exn(p, xs, ys) { let len_xs = xs.length; let len_ys = ys.length; if (len_xs === len_ys) { return unsafe_loop(0, len_xs, p, xs, ys); } else { return false; } } export { reverse_range, reverse_in_place, reverse, reverse_of_list, filter, filter_map, range, map2i, tolist_aux, to_list_map, to_list_map_acc, of_list_map, rfind_with_index, rfind_and_split, find_with_index, find_and_split, exists, is_empty, unsafe_loop, for_all2_no_exn, } /* No side effect */