@@ -16,6 +16,7 @@ module Data.StrMap
16
16
, toAscUnfoldable
17
17
, fromFoldable
18
18
, fromFoldableWith
19
+ , fromRecord
19
20
, delete
20
21
, pop
21
22
, member
@@ -46,7 +47,6 @@ import Prelude
46
47
47
48
import Control.Monad.Eff (Eff , runPure , foreachE )
48
49
import Control.Monad.ST as ST
49
-
50
50
import Data.Array as A
51
51
import Data.Eq (class Eq1 )
52
52
import Data.Foldable (class Foldable , foldl , foldr , for_ )
@@ -60,6 +60,8 @@ import Data.Traversable (class Traversable, traverse)
60
60
import Data.TraversableWithIndex (class TraversableWithIndex , traverseWithIndex )
61
61
import Data.Tuple (Tuple (..), fst , uncurry )
62
62
import Data.Unfoldable (class Unfoldable )
63
+ import Type.Row.Homogeneous (class Homogeneous )
64
+ import Unsafe.Coerce (unsafeCoerce )
63
65
64
66
-- | `StrMap a` represents a map from `String`s to values of type `a`.
65
67
foreign import data StrMap :: Type -> Type
@@ -235,6 +237,10 @@ fromFoldableWith f l = pureST (do
235
237
for_ l (\(Tuple k v) -> runFn4 _lookupST v (f v) k s >>= SM .poke s k)
236
238
pure s)
237
239
240
+ -- | Create a map from a homogeneous record (all attributes have the same type).
241
+ fromRecord :: forall r t . Homogeneous r t => Record r -> StrMap t
242
+ fromRecord = unsafeCoerce
243
+
238
244
foreign import toArrayWithKey :: forall a b . (String -> a -> b ) -> StrMap a -> Array b
239
245
240
246
-- | Unfolds a map into a list of key/value pairs
0 commit comments