Skip to content

Commit 5ad97d6

Browse files
committed
extend Foldable (foldl', null, length)
1 parent a3373e9 commit 5ad97d6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Data/HashMap/Base.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,15 @@ instance Functor (HashMap k) where
197197
fmap = map
198198

199199
instance Foldable.Foldable (HashMap k) where
200-
foldr f = foldrWithKey (const f)
200+
foldr = Data.HashMap.Base.foldr
201+
{-# INLINE foldr #-}
202+
foldl' = Data.HashMap.Base.foldl'
203+
{-# INLINE foldl' #-}
204+
null = Data.HashMap.Base.null
205+
{-# INLINE null #-}
206+
length = Data.HashMap.Base.size
207+
{-# INLINE length #-}
208+
201209

202210
#if __GLASGOW_HASKELL__ >= 711
203211
instance (Eq k, Hashable k) => Semigroup (HashMap k v) where
@@ -1530,7 +1538,7 @@ intersectionWithKey f a b = foldlWithKey' go empty a
15301538
-- | /O(n)/ Reduce this map by applying a binary operator to all
15311539
-- elements, using the given starting value (typically the
15321540
-- left-identity of the operator). Each application of the operator
1533-
-- is evaluated before using the result in the next application.
1541+
-- is evaluated before using the result in the next application.
15341542
-- This function is strict in the starting value.
15351543
foldl' :: (a -> v -> a) -> a -> HashMap k v -> a
15361544
foldl' f = foldlWithKey' (\ z _ v -> f z v)
@@ -1539,7 +1547,7 @@ foldl' f = foldlWithKey' (\ z _ v -> f z v)
15391547
-- | /O(n)/ Reduce this map by applying a binary operator to all
15401548
-- elements, using the given starting value (typically the
15411549
-- left-identity of the operator). Each application of the operator
1542-
-- is evaluated before using the result in the next application.
1550+
-- is evaluated before using the result in the next application.
15431551
-- This function is strict in the starting value.
15441552
foldlWithKey' :: (a -> k -> v -> a) -> a -> HashMap k v -> a
15451553
foldlWithKey' f = go

Data/HashSet/Base.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ instance Ord1 HashSet where
140140
instance Foldable.Foldable HashSet where
141141
foldr = Data.HashSet.Base.foldr
142142
{-# INLINE foldr #-}
143+
foldl' = Data.HashSet.Base.foldl'
144+
{-# INLINE foldl' #-}
145+
toList = Data.HashSet.Base.toList
146+
{-# INLINE toList #-}
147+
null = Data.HashSet.Base.null
148+
{-# INLINE null #-}
149+
length = Data.HashSet.Base.size
150+
{-# INLINE length #-}
143151

144152
#if __GLASGOW_HASKELL__ >= 711
145153
instance (Hashable a, Eq a) => Semigroup (HashSet a) where

0 commit comments

Comments
 (0)