Skip to content

Commit b863b82

Browse files
authored
Merge pull request #96 from matthewleon/st-partial
partial functions for ST arrays
2 parents 9a5770d + 32b5a90 commit b863b82

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Data/Array/ST/Partial.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
exports.peekSTArray = function (xs) {
4+
return function (i) {
5+
return function () {
6+
return xs[i];
7+
};
8+
};
9+
};
10+
11+
exports.pokeSTArray = function (xs) {
12+
return function (i) {
13+
return function (a) {
14+
return function () {
15+
xs[i] = a;
16+
return {};
17+
};
18+
};
19+
};
20+
};

src/Data/Array/ST/Partial.purs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- | Partial functions for working with mutable arrays using the `ST` effect.
2+
-- |
3+
-- | This module is particularly helpful when performance is very important.
4+
5+
module Data.Array.ST.Partial
6+
( peekSTArray
7+
, pokeSTArray
8+
) where
9+
10+
import Control.Monad.Eff (Eff)
11+
import Control.Monad.ST (ST)
12+
import Data.Array.ST (STArray)
13+
import Data.Unit (Unit)
14+
15+
-- | Read the value at the specified index in a mutable array.
16+
foreign import peekSTArray
17+
:: forall a h r
18+
. Partial
19+
=> STArray h a
20+
-> Int
21+
-> Eff (st :: ST h | r) a
22+
23+
-- | Change the value at the specified index in a mutable array.
24+
foreign import pokeSTArray
25+
:: forall a h r
26+
. Partial
27+
=> STArray h a
28+
-> Int
29+
-> a
30+
-> Eff (st :: ST h | r) Unit

0 commit comments

Comments
 (0)