git.iko.soy/rowtype-yoga/yoga-r3f
on main help sign in
113 lines 2.4 kB history raw
1function newSTArray() {
2 return [];
3}
4export { newSTArray as new };
6export const peekImpl = function (just, nothing, i, xs) {
7 return i >= 0 && i < xs.length ? just(xs[i]) : nothing;
8};
10export const pokeImpl = function (i, a, xs) {
11 var ret = i >= 0 && i < xs.length;
12 if (ret) xs[i] = a;
13 return ret;
14};
16export const lengthImpl = function (xs) {
17 return xs.length;
18};
20export const popImpl = function (just, nothing, xs) {
21 return xs.length > 0 ? just(xs.pop()) : nothing;
22};
24export const pushAllImpl = function (as, xs) {
25 return xs.push.apply(xs, as);
26};
28export const shiftImpl = function (just, nothing, xs) {
29 return xs.length > 0 ? just(xs.shift()) : nothing;
30};
32export const unshiftAllImpl = function (as, xs) {
33 return xs.unshift.apply(xs, as);
34};
36export const spliceImpl = function (i, howMany, bs, xs) {
37 return xs.splice.apply(xs, [i, howMany].concat(bs));
38};
40function unsafeFreezeThawImpl(xs) {
41 return xs;
44export const unsafeFreezeImpl = unsafeFreezeThawImpl;
46export const unsafeThawImpl = unsafeFreezeThawImpl;
48function copyImpl(xs) {
49 return xs.slice();
52export const freezeImpl = copyImpl;
54export const thawImpl = copyImpl;
56export const cloneImpl = copyImpl;
58export const sortByImpl = (function () {
59 function mergeFromTo(compare, fromOrdering, xs1, xs2, from, to) {
60 var mid;
61 var i;
62 var j;
63 var k;
64 var x;
65 var y;
66 var c;
68 mid = from + ((to - from) >> 1);
69 if (mid - from > 1) mergeFromTo(compare, fromOrdering, xs2, xs1, from, mid);
70 if (to - mid > 1) mergeFromTo(compare, fromOrdering, xs2, xs1, mid, to);
72 i = from;
73 j = mid;
74 k = from;
75 while (i < mid && j < to) {
76 x = xs2[i];
77 y = xs2[j];
78 c = fromOrdering(compare(x)(y));
79 if (c > 0) {
80 xs1[k++] = y;
81 ++j;
82 } else {
83 xs1[k++] = x;
84 ++i;
85 }
86 }
87 while (i < mid) {
88 xs1[k++] = xs2[i++];
89 }
90 while (j < to) {
91 xs1[k++] = xs2[j++];
92 }
93 }
95 return function (compare, fromOrdering, xs) {
96 if (xs.length < 2) return xs;
98 mergeFromTo(compare, fromOrdering, xs, xs.slice(0), 0, xs.length);
100 return xs;
101 };
102})();
104export const toAssocArrayImpl = function (xs) {
105 var n = xs.length;
106 var as = new Array(n);
107 for (var i = 0; i < n; i++) as[i] = { value: xs[i], index: i };
108 return as;
109};
111export const pushImpl = function (a, xs) {
112 return xs.push(a);
113};