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 140
140
141
141
instance eqStrMap :: (P.Eq a) => P.Eq (StrMap a)
142
142
143
+ instance foldableStrMap :: Foldable StrMap
144
+
143
145
instance functorStrMap :: P.Functor StrMap
144
146
145
147
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
37
37
import Data.Maybe
38
38
import Data.Function
39
39
import Data.Tuple
40
- import Data.Foldable (foldl )
40
+ import Data.Foldable (Foldable , foldl , foldr )
41
41
import Data.Monoid
42
42
import Data.Monoid.All
43
43
@@ -55,8 +55,6 @@ foreign import _fmapStrMap
55
55
instance functorStrMap :: P.Functor StrMap where
56
56
(<$>) f m = runFn2 _fmapStrMap m f
57
57
58
- -- It would be nice to have a Foldable instance, but we're essentially unordered
59
-
60
58
foreign import _foldM
61
59
" function _foldM(bind) {\
62
60
\ return function(f) {\
@@ -83,6 +81,11 @@ foldMap f = fold (\acc k v -> acc P.<> f k v) mempty
83
81
foldM :: forall a m z . (P.Monad m ) => (z -> String -> a -> m z ) -> z -> StrMap a -> m z
84
82
foldM f z = _foldM P .(>>=) f (P .pure z)
85
83
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
+
86
89
-- Unfortunately the above are not short-circuitable (consider using purescript-machines)
87
90
-- so we need special cases:
88
91
You can’t perform that action at this time.
0 commit comments