Skip to content

Commit

Permalink
Merge pull request #109 from purescript/document-push-return-value
Browse files Browse the repository at this point in the history
Document and test return values of pushSTArray
  • Loading branch information
hdgarrood authored Jun 20, 2017
2 parents 340b2d4 + f3997ca commit ebde72f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Data/Array/ST.purs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ foreign import pokeSTArray
:: forall a h r
. STArray h a -> Int -> a -> Eff (st :: ST h | r) Boolean

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

-- | Append the values in an immutable array to the end of a mutable array.
-- | Returns the new length of the mutable array.
foreign import pushAllSTArray
:: forall a h r
. STArray h a
Expand Down
12 changes: 12 additions & 0 deletions test/Test/Data/Array/ST.purs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ testArrayST = do
void $ pushSTArray arr 4
pure arr) == [1, 2, 3, 4]

log "pushSTArray should return the new length of the array"

assert $ pureST (do
arr <- thaw [unit, unit, unit]
pushSTArray arr unit) == 4

log "pushAllSTArray should append multiple values to the end of the array"

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

log "pushAllSTArray should return the new length of the array"

assert $ pureST (do
arr <- thaw [unit, unit, unit]
pushAllSTArray arr [unit, unit]) == 5

log "peekSTArray should return Nothing when peeking a value outside the array bounds"

assert $ isNothing $ pureST (do
Expand Down

0 comments on commit ebde72f

Please sign in to comment.