Skip to content

Commit 7286121

Browse files
Add foreign implementation for push (#240)
* Add foreign implementation for push * Use foreign implementation for push * Add changelog entry * Update src/Data/Array/ST.js Co-authored-by: Thomas Honeyman <[email protected]> * Update ST.purs --------- Co-authored-by: Thomas Honeyman <[email protected]>
1 parent ad76064 commit 7286121

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ New features:
1111
Bugfixes:
1212

1313
Other improvements:
14+
- Implements `ST.push` via a call to JavaScript's native `push` instead of `pushAll` (#236 by @i-am-the-slime)
1415

1516
## [v7.2.1](https://github.com/purescript/purescript-arrays/releases/tag/v7.2.1) - 2023-06-13
1617

src/Data/Array/ST.js

+4
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ export const toAssocArrayImpl = function (xs) {
105105
for (var i = 0; i < n; i++) as[i] = { value: xs[i], index: i };
106106
return as;
107107
};
108+
109+
export const pushImpl = function (a, xs) {
110+
return xs.push(a);
111+
};

src/Data/Array/ST.purs

+4-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ foreign import popImpl
181181

182182
-- | Append an element to the end of a mutable array. Returns the new length of
183183
-- | the array.
184-
push :: forall h a. a -> STArray h a -> ST h Int
185-
push a = runSTFn2 pushAllImpl [ a ]
184+
push :: forall h a. a -> (STArray h a) -> ST h Int
185+
push = runSTFn2 pushImpl
186+
187+
foreign import pushImpl :: forall h a. STFn2 a (STArray h a) h Int
186188

187189
-- | Append the values in an immutable array to the end of a mutable array.
188190
-- | Returns the new length of the mutable array.

0 commit comments

Comments
 (0)