Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit d5ec2b3

Browse files
committed
Export toArrayWithKey function
1 parent 92ac171 commit d5ec2b3

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/Data/StrMap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ exports._lookupST = function (no, yes, k, m) {
106106
};
107107
};
108108

109-
function _collect(f) {
109+
function toArrayWithKey(f) {
110110
return function (m) {
111111
var r = [];
112112
for (var k in m) {
@@ -118,8 +118,8 @@ function _collect(f) {
118118
};
119119
}
120120

121-
exports._collect = _collect;
121+
exports.toArrayWithKey = toArrayWithKey;
122122

123-
exports.keys = Object.keys || _collect(function (k) {
123+
exports.keys = Object.keys || toArrayWithKey(function (k) {
124124
return function () { return k; };
125125
});

src/Data/StrMap.purs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module Data.StrMap
3939
, freezeST
4040
, runST
4141
, pureST
42+
, toArrayWithKey
4243
) where
4344

4445
import Prelude
@@ -219,27 +220,27 @@ fromFoldableWith f l = pureST (do
219220
for_ l (\(Tuple k v) -> runFn4 _lookupST v (f v) k s >>= SM.poke s k)
220221
pure s)
221222

222-
foreign import _collect :: forall a b . (String -> a -> b) -> StrMap a -> Array b
223+
foreign import toArrayWithKey :: forall a b . (String -> a -> b) -> StrMap a -> Array b
223224

224225
-- | Unfolds a map into a list of key/value pairs
225226
toUnfoldable :: forall f a. Unfoldable f => StrMap a -> f (Tuple String a)
226-
toUnfoldable = A.toUnfoldable <<< _collect Tuple
227+
toUnfoldable = A.toUnfoldable <<< toArrayWithKey Tuple
227228

228229
-- | Unfolds a map into a list of key/value pairs which is guaranteed to be
229230
-- | sorted by key
230231
toAscUnfoldable :: forall f a. Unfoldable f => StrMap a -> f (Tuple String a)
231-
toAscUnfoldable = A.toUnfoldable <<< A.sortWith fst <<< _collect Tuple
232+
toAscUnfoldable = A.toUnfoldable <<< A.sortWith fst <<< toArrayWithKey Tuple
232233

233234
-- Internal
234235
toArray :: forall a. StrMap a -> Array (Tuple String a)
235-
toArray = _collect Tuple
236+
toArray = toArrayWithKey Tuple
236237

237238
-- | Get an array of the keys in a map
238239
foreign import keys :: forall a. StrMap a -> Array String
239240

240241
-- | Get a list of the values in a map
241242
values :: forall a. StrMap a -> Array a
242-
values = _collect (\_ v -> v)
243+
values = toArrayWithKey (\_ v -> v)
243244

244245
-- | Compute the union of two maps, preferring the first map in the case of
245246
-- | duplicate keys.

0 commit comments

Comments
 (0)