Skip to content

Commit 568f07e

Browse files
Update ST FFI to use StFns (#234)
* Update ST FFI to use StFns * Add changelog * Update bower.json Co-authored-by: Thomas Honeyman <[email protected]> * Move doc comment --------- Co-authored-by: Thomas Honeyman <[email protected]>
1 parent a903f6b commit 568f07e

File tree

6 files changed

+125
-159
lines changed

6 files changed

+125
-159
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ New features:
2020

2121
Other improvements:
2222
- Use more efficient implementation for `mapWithIndex` (#233 by @JordanMartinez)
23+
- Updates `ST` FFI to use uncurried functions via `STFnX` types (#234 by @JordanMartinez)
2324

2425
## [v7.1.0](https://github.com/purescript/purescript-arrays/releases/tag/v7.1.0) - 2022-08-06
2526

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"purescript-partial": "^4.0.0",
2424
"purescript-prelude": "^6.0.0",
2525
"purescript-safe-coerce": "^2.0.0",
26-
"purescript-st": "^6.0.0",
26+
"purescript-st": "^6.2.0",
2727
"purescript-tailrec": "^6.0.0",
2828
"purescript-tuples": "^7.0.0",
2929
"purescript-unfoldable": "^6.0.0",

src/Data/Array/ST.js

Lines changed: 38 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,57 @@
1-
function newSTArray () {
1+
function newSTArray() {
22
return [];
33
}
44
export { newSTArray as new };
55

6-
export const peekImpl = function (just) {
7-
return function (nothing) {
8-
return function (i) {
9-
return function (xs) {
10-
return function () {
11-
return i >= 0 && i < xs.length ? just(xs[i]) : nothing;
12-
};
13-
};
14-
};
15-
};
6+
export const peekImpl = function (just, nothing, i, xs) {
7+
return i >= 0 && i < xs.length ? just(xs[i]) : nothing;
168
};
179

18-
export const poke = function (i) {
19-
return function (a) {
20-
return function (xs) {
21-
return function () {
22-
var ret = i >= 0 && i < xs.length;
23-
if (ret) xs[i] = a;
24-
return ret;
25-
};
26-
};
27-
};
10+
export const pokeImpl = function (i, a, xs) {
11+
var ret = i >= 0 && i < xs.length;
12+
if (ret) xs[i] = a;
13+
return ret;
2814
};
2915

30-
export const length = function (xs) {
31-
return function () {
32-
return xs.length;
33-
};
16+
export const lengthImpl = function (xs) {
17+
return xs.length;
3418
};
3519

36-
export const popImpl = function (just) {
37-
return function (nothing) {
38-
return function (xs) {
39-
return function () {
40-
return xs.length > 0 ? just(xs.pop()) : nothing;
41-
};
42-
};
43-
};
20+
export const popImpl = function (just, nothing, xs) {
21+
return xs.length > 0 ? just(xs.pop()) : nothing;
4422
};
4523

46-
export const pushAll = function (as) {
47-
return function (xs) {
48-
return function () {
49-
return xs.push.apply(xs, as);
50-
};
51-
};
24+
export const pushAllImpl = function (as, xs) {
25+
return xs.push.apply(xs, as);
5226
};
5327

54-
export const shiftImpl = function (just) {
55-
return function (nothing) {
56-
return function (xs) {
57-
return function () {
58-
return xs.length > 0 ? just(xs.shift()) : nothing;
59-
};
60-
};
61-
};
28+
export const shiftImpl = function (just, nothing, xs) {
29+
return xs.length > 0 ? just(xs.shift()) : nothing;
6230
};
6331

64-
export const unshiftAll = function (as) {
65-
return function (xs) {
66-
return function () {
67-
return xs.unshift.apply(xs, as);
68-
};
69-
};
32+
export const unshiftAllImpl = function (as, xs) {
33+
return xs.unshift.apply(xs, as);
7034
};
7135

72-
export const splice = function (i) {
73-
return function (howMany) {
74-
return function (bs) {
75-
return function (xs) {
76-
return function () {
77-
return xs.splice.apply(xs, [i, howMany].concat(bs));
78-
};
79-
};
80-
};
81-
};
36+
export const spliceImpl = function (i, howMany, bs, xs) {
37+
return xs.splice.apply(xs, [i, howMany].concat(bs));
8238
};
8339

84-
export const unsafeFreeze = function (xs) {
85-
return function () {
86-
return xs;
87-
};
88-
};
40+
function unsafeFreezeThawImpl(xs) {
41+
return xs;
42+
}
8943

90-
export const unsafeThaw = function (xs) {
91-
return function () {
92-
return xs;
93-
};
94-
};
44+
export const unsafeFreezeImpl = unsafeFreezeThawImpl;
45+
46+
export const unsafeThawImpl = unsafeFreezeThawImpl;
9547

9648
function copyImpl(xs) {
97-
return function () {
98-
return xs.slice();
99-
};
49+
return xs.slice();
10050
}
10151

102-
export const freeze = copyImpl;
52+
export const freezeImpl = copyImpl;
10353

104-
export const thaw = copyImpl;
54+
export const thawImpl = copyImpl;
10555

10656
export const sortByImpl = (function () {
10757
function mergeFromTo(compare, fromOrdering, xs1, xs2, from, to) {
@@ -127,8 +77,7 @@ export const sortByImpl = (function () {
12777
if (c > 0) {
12878
xs1[k++] = y;
12979
++j;
130-
}
131-
else {
80+
} else {
13281
xs1[k++] = x;
13382
++i;
13483
}
@@ -141,26 +90,18 @@ export const sortByImpl = (function () {
14190
}
14291
}
14392

144-
return function (compare) {
145-
return function (fromOrdering) {
146-
return function (xs) {
147-
return function () {
148-
if (xs.length < 2) return xs;
93+
return function (compare, fromOrdering, xs) {
94+
if (xs.length < 2) return xs;
14995

150-
mergeFromTo(compare, fromOrdering, xs, xs.slice(0), 0, xs.length);
96+
mergeFromTo(compare, fromOrdering, xs, xs.slice(0), 0, xs.length);
15197

152-
return xs;
153-
};
154-
};
155-
};
98+
return xs;
15699
};
157100
})();
158101

159-
export const toAssocArray = function (xs) {
160-
return function () {
161-
var n = xs.length;
162-
var as = new Array(n);
163-
for (var i = 0; i < n; i++) as[i] = { value: xs[i], index: i };
164-
return as;
165-
};
102+
export const toAssocArrayImpl = function (xs) {
103+
var n = xs.length;
104+
var as = new Array(n);
105+
for (var i = 0; i < n; i++) as[i] = { value: xs[i], index: i };
106+
return as;
166107
};

0 commit comments

Comments
 (0)