@@ -16,6 +16,7 @@ module Data.StrMap
1616 , toAscUnfoldable
1717 , fromFoldable
1818 , fromFoldableWith
19+ , fromRecord
1920 , delete
2021 , pop
2122 , member
@@ -46,7 +47,6 @@ import Prelude
4647
4748import Control.Monad.Eff (Eff , runPure , foreachE )
4849import Control.Monad.ST as ST
49-
5050import Data.Array as A
5151import Data.Eq (class Eq1 )
5252import Data.Foldable (class Foldable , foldl , foldr , for_ )
@@ -60,6 +60,8 @@ import Data.Traversable (class Traversable, traverse)
6060import Data.TraversableWithIndex (class TraversableWithIndex , traverseWithIndex )
6161import Data.Tuple (Tuple (..), fst , uncurry )
6262import Data.Unfoldable (class Unfoldable )
63+ import Type.Row.Homogeneous (class Homogeneous )
64+ import Unsafe.Coerce (unsafeCoerce )
6365
6466-- | `StrMap a` represents a map from `String`s to values of type `a`.
6567foreign import data StrMap :: Type -> Type
@@ -235,6 +237,10 @@ fromFoldableWith f l = pureST (do
235237 for_ l (\(Tuple k v) -> runFn4 _lookupST v (f v) k s >>= SM .poke s k)
236238 pure s)
237239
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+
238244foreign import toArrayWithKey :: forall a b . (String -> a -> b ) -> StrMap a -> Array b
239245
240246-- | Unfolds a map into a list of key/value pairs
0 commit comments