@@ -15,6 +15,7 @@ module Foreign.Object
15
15
, toAscUnfoldable
16
16
, fromFoldable
17
17
, fromFoldableWith
18
+ , fromFoldableWithIndex
18
19
, fromHomogeneous
19
20
, delete
20
21
, pop
@@ -49,7 +50,7 @@ import Control.Monad.ST as ST
49
50
import Data.Array as A
50
51
import Data.Eq (class Eq1 )
51
52
import Data.Foldable (class Foldable , foldl , foldr , for_ )
52
- import Data.FoldableWithIndex (class FoldableWithIndex )
53
+ import Data.FoldableWithIndex (class FoldableWithIndex , forWithIndex_ )
53
54
import Data.Function.Uncurried (Fn2 , runFn2 , Fn4 , runFn4 )
54
55
import Data.FunctorWithIndex (class FunctorWithIndex )
55
56
import Data.Maybe (Maybe (..), maybe , fromMaybe )
@@ -221,6 +222,14 @@ fromFoldable l = runST do
221
222
ST .foreach (A .fromFoldable l) \(Tuple k v) -> void $ OST .poke k v s
222
223
pure s
223
224
225
+ -- | Create an `Object a` from an indexed foldable collection, using the
226
+ -- | specified function for converting the index to `String`
227
+ fromFoldableWithIndex :: forall f k v . FoldableWithIndex k f => (k -> String ) -> f v -> Object v
228
+ fromFoldableWithIndex f l = runST do
229
+ s <- OST .new
230
+ forWithIndex_ l \k v -> OST .poke (f k) v s
231
+ pure s
232
+
224
233
foreign import _lookupST :: forall a r z . Fn4 z (a -> z ) String (STObject r a ) (ST r z )
225
234
226
235
-- | Create an `Object a` from a foldable collection of key/value pairs, using the
0 commit comments