Skip to content

Commit dff0308

Browse files
authored
Rename Data.Array.ST.empty (#191)
* Rename Data.Array.ST.empty * Deprecate Data.Array.ST.empty
1 parent fab2c23 commit dff0308

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

src/Data/Array.purs

+5-5
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,10 @@ group' = groupAll
976976
groupBy :: forall a. (a -> a -> Boolean) -> Array a -> Array (NonEmptyArray a)
977977
groupBy op xs =
978978
ST.run do
979-
result <- STA.empty
979+
result <- STA.new
980980
iter <- STAI.iterator (xs !! _)
981981
STAI.iterate iter \x -> void do
982-
sub <- STA.empty
982+
sub <- STA.new
983983
_ <- STA.push x sub
984984
STAI.pushWhile (op x) iter sub
985985
grp <- STA.unsafeFreeze sub
@@ -1052,7 +1052,7 @@ nubBy comp xs = case head indexedAndSorted of
10521052
-- |
10531053
nubByEq :: forall a. (a -> a -> Boolean) -> Array a -> Array a
10541054
nubByEq eq xs = ST.run do
1055-
arr <- STA.empty
1055+
arr <- STA.new
10561056
ST.foreach xs \x -> do
10571057
e <- not <<< any (_ `eq` x) <$> (STA.unsafeFreeze arr)
10581058
when e $ void $ STA.push x arr
@@ -1201,8 +1201,8 @@ zip = zipWith Tuple
12011201
unzip :: forall a b. Array (Tuple a b) -> Tuple (Array a) (Array b)
12021202
unzip xs =
12031203
ST.run do
1204-
fsts <- STA.empty
1205-
snds <- STA.empty
1204+
fsts <- STA.new
1205+
snds <- STA.new
12061206
iter <- STAI.iterator (xs !! _)
12071207
STAI.iterate iter \(Tuple fst snd) -> do
12081208
void $ STA.push fst fsts

src/Data/Array/ST.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
exports.empty = function () {
3+
exports["new"] = function () {
44
return [];
55
};
66

src/Data/Array/ST.purs

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Data.Array.ST
77
, Assoc
88
, run
99
, withArray
10+
, new
1011
, empty
1112
, peek
1213
, poke
@@ -33,6 +34,7 @@ import Prelude
3334
import Control.Monad.ST as ST
3435
import Control.Monad.ST (ST, Region)
3536
import Data.Maybe (Maybe(..))
37+
import Prim.TypeError (class Warn, Text)
3638

3739
-- | A reference to a mutable array.
3840
-- |
@@ -75,8 +77,11 @@ foreign import unsafeFreeze :: forall h a. STArray h a -> ST h (Array a)
7577
-- | array must not be used afterward.
7678
foreign import unsafeThaw :: forall h a. Array a -> ST h (STArray h a)
7779

78-
-- | Create an empty mutable array.
79-
foreign import empty :: forall h a. ST h (STArray h a)
80+
-- | Create a new, empty mutable array.
81+
foreign import new :: forall h a. ST h (STArray h a)
82+
83+
empty :: forall h a. Warn (Text "'Data.Array.ST.empty' is deprecated, use 'Data.Array.ST.new' instead") => ST h (STArray h a)
84+
empty = new
8085

8186
-- | Create a mutable copy of an immutable array.
8287
foreign import thaw :: forall h a. Array a -> ST h (STArray h a)

test/Test/Data/Array/ST.purs

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ testArrayST = do
1818
log "run should produce an immutable array by running a constructor operation"
1919

2020
assert $ STA.run (do
21-
arr <- STA.empty
21+
arr <- STA.new
2222
void $ STA.push 1 arr
2323
void $ STA.push 2 arr
2424
pure arr) == [1, 2]
@@ -31,7 +31,7 @@ testArrayST = do
3131

3232
log "empty should produce an empty array"
3333

34-
assert $ STA.run STA.empty == nil
34+
assert $ STA.run STA.new == nil
3535

3636
log "thaw should produce an STArray from a standard array"
3737

@@ -63,13 +63,13 @@ testArrayST = do
6363
log "pop should return Nothing when given an empty array"
6464

6565
assert $ isNothing $ ST.run (do
66-
arr <- STA.empty
66+
arr <- STA.new
6767
STA.pop arr)
6868

6969
log "push should append a value to the end of the array"
7070

7171
assert $ STA.run (do
72-
arr <- STA.empty
72+
arr <- STA.new
7373
void $ STA.push 1 arr
7474
void $ STA.push 2 arr
7575
pure arr) == [1, 2]
@@ -88,7 +88,7 @@ testArrayST = do
8888
log "pushAll should append multiple values to the end of the array"
8989

9090
assert $ STA.run (do
91-
arr <- STA.empty
91+
arr <- STA.new
9292
void $ STA.pushAll [1, 2] arr
9393
pure arr) == [1, 2]
9494

@@ -106,15 +106,15 @@ testArrayST = do
106106
log "peek should return Nothing when peeking a value outside the array bounds"
107107

108108
assert $ isNothing $ ST.run (do
109-
arr <- STA.empty
109+
arr <- STA.new
110110
STA.peek 0 arr)
111111

112112
assert $ isNothing $ ST.run (do
113113
arr <- STA.thaw [1]
114114
STA.peek 1 arr)
115115

116116
assert $ isNothing $ ST.run (do
117-
arr <- STA.empty
117+
arr <- STA.new
118118
STA.peek (-1) arr)
119119

120120
log "peek should return the value at the specified index"
@@ -140,7 +140,7 @@ testArrayST = do
140140
log "poke should return false when attempting to modify a value outside the array bounds"
141141

142142
assert $ not $ ST.run (do
143-
arr <- STA.empty
143+
arr <- STA.new
144144
STA.poke 0 10 arr)
145145

146146
assert $ not $ ST.run (do
@@ -181,13 +181,13 @@ testArrayST = do
181181
log "shift should return Nothing when given an empty array"
182182

183183
assert $ isNothing $ ST.run (do
184-
arr <- STA.empty
184+
arr <- STA.new
185185
STA.shift arr)
186186

187187
log "unshift should append a value to the front of the array"
188188

189189
assert $ STA.run (do
190-
arr <- STA.empty
190+
arr <- STA.new
191191
void $ STA.unshift 1 arr
192192
void $ STA.unshift 2 arr
193193
pure arr) == [2, 1]
@@ -206,7 +206,7 @@ testArrayST = do
206206
log "unshiftAll should append multiple values to the front of the array"
207207

208208
assert $ STA.run (do
209-
arr <- STA.empty
209+
arr <- STA.new
210210
void $ STA.unshiftAll [1, 2] arr
211211
pure arr) == [1, 2]
212212

0 commit comments

Comments
 (0)