diff --git a/CHANGELOG.md b/CHANGELOG.md index a3ec97e..9540992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ New features: Bugfixes: Other improvements: + - Implements `ST.push` via a call to JavaScript's native `push` instead of `pushAll` (#236 by @i-am-the-slime) ## [v7.2.1](https://github.com/purescript/purescript-arrays/releases/tag/v7.2.1) - 2023-06-13 diff --git a/src/Data/Array/ST.js b/src/Data/Array/ST.js index 3f4fa21..2795f00 100644 --- a/src/Data/Array/ST.js +++ b/src/Data/Array/ST.js @@ -105,3 +105,7 @@ export const toAssocArrayImpl = function (xs) { for (var i = 0; i < n; i++) as[i] = { value: xs[i], index: i }; return as; }; + +export const pushImpl = function (a, xs) { + return xs.push(a); +}; diff --git a/src/Data/Array/ST.purs b/src/Data/Array/ST.purs index e95864c..5ff3c1a 100644 --- a/src/Data/Array/ST.purs +++ b/src/Data/Array/ST.purs @@ -181,8 +181,10 @@ foreign import popImpl -- | Append an element to the end of a mutable array. Returns the new length of -- | the array. -push :: forall h a. a -> STArray h a -> ST h Int -push a = runSTFn2 pushAllImpl [ a ] +push :: forall h a. a -> (STArray h a) -> ST h Int +push = runSTFn2 pushImpl + +foreign import pushImpl :: forall h a. STFn2 a (STArray h a) h Int -- | Append the values in an immutable array to the end of a mutable array. -- | Returns the new length of the mutable array.