This repository was archived by the owner on Oct 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change 140140
141141 instance eqStrMap :: (P.Eq a) => P.Eq (StrMap a)
142142
143+ instance foldableStrMap :: Foldable StrMap
144+
143145 instance functorStrMap :: P.Functor StrMap
144146
145147 instance semigroupStrMap :: (P.Semigroup a) => P.Semigroup (StrMap a)
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ import qualified Data.Array as A
3737import Data.Maybe
3838import Data.Function
3939import Data.Tuple
40- import Data.Foldable (foldl )
40+ import Data.Foldable (Foldable , foldl , foldr )
4141import Data.Monoid
4242import Data.Monoid.All
4343
@@ -55,8 +55,6 @@ foreign import _fmapStrMap
5555instance functorStrMap :: P.Functor StrMap where
5656 (<$>) f m = runFn2 _fmapStrMap m f
5757
58- -- It would be nice to have a Foldable instance, but we're essentially unordered
59-
6058foreign import _foldM
6159 " function _foldM(bind) {\
6260 \ return function(f) {\
@@ -83,6 +81,11 @@ foldMap f = fold (\acc k v -> acc P.<> f k v) mempty
8381foldM :: forall a m z . (P.Monad m ) => (z -> String -> a -> m z ) -> z -> StrMap a -> m z
8482foldM f z = _foldM P .(>>=) f (P .pure z)
8583
84+ instance foldableStrMap :: Foldable StrMap where
85+ foldl f = fold (\z _ -> f z)
86+ foldr f z m = foldr f z (values m)
87+ foldMap f = foldMap (P .const f)
88+
8689-- Unfortunately the above are not short-circuitable (consider using purescript-machines)
8790-- so we need special cases:
8891
You can’t perform that action at this time.
0 commit comments