Skip to content

Commit ebde72f

Browse files
authored
Merge pull request #109 from purescript/document-push-return-value
Document and test return values of pushSTArray
2 parents 340b2d4 + f3997ca commit ebde72f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Data/Array/ST.purs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ foreign import pokeSTArray
100100
:: forall a h r
101101
. STArray h a -> Int -> a -> Eff (st :: ST h | r) Boolean
102102

103-
-- | Append an element to the end of a mutable array.
103+
-- | Append an element to the end of a mutable array. Returns the new length of
104+
-- | the array.
104105
pushSTArray :: forall a h r. STArray h a -> a -> Eff (st :: ST h | r) Int
105106
pushSTArray arr a = pushAllSTArray arr [a]
106107

107108
-- | Append the values in an immutable array to the end of a mutable array.
109+
-- | Returns the new length of the mutable array.
108110
foreign import pushAllSTArray
109111
:: forall a h r
110112
. STArray h a

test/Test/Data/Array/ST.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ testArrayST = do
4242
void $ pushSTArray arr 4
4343
pure arr) == [1, 2, 3, 4]
4444

45+
log "pushSTArray should return the new length of the array"
46+
47+
assert $ pureST (do
48+
arr <- thaw [unit, unit, unit]
49+
pushSTArray arr unit) == 4
50+
4551
log "pushAllSTArray should append multiple values to the end of the array"
4652

4753
assert $ run (do
@@ -54,6 +60,12 @@ testArrayST = do
5460
void $ pushAllSTArray arr [4, 5, 6]
5561
pure arr) == [1, 2, 3, 4, 5, 6]
5662

63+
log "pushAllSTArray should return the new length of the array"
64+
65+
assert $ pureST (do
66+
arr <- thaw [unit, unit, unit]
67+
pushAllSTArray arr [unit, unit]) == 5
68+
5769
log "peekSTArray should return Nothing when peeking a value outside the array bounds"
5870

5971
assert $ isNothing $ pureST (do

0 commit comments

Comments
 (0)