Skip to content

Extend Foldable (foldl', null, length) #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Data/HashMap/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ instance Functor (HashMap k) where
fmap = map

instance Foldable.Foldable (HashMap k) where
foldr f = foldrWithKey (const f)
foldr = Data.HashMap.Base.foldr
{-# INLINE foldr #-}
foldl' = Data.HashMap.Base.foldl'
{-# INLINE foldl' #-}
#if MIN_VERSION_base(4,8,0)
null = Data.HashMap.Base.null
{-# INLINE null #-}
length = Data.HashMap.Base.size
{-# INLINE length #-}
#endif

#if __GLASGOW_HASKELL__ >= 711
instance (Eq k, Hashable k) => Semigroup (HashMap k v) where
Expand Down Expand Up @@ -1530,7 +1539,7 @@ intersectionWithKey f a b = foldlWithKey' go empty a
-- | /O(n)/ Reduce this map by applying a binary operator to all
-- elements, using the given starting value (typically the
-- left-identity of the operator). Each application of the operator
-- is evaluated before using the result in the next application.
-- is evaluated before using the result in the next application.
-- This function is strict in the starting value.
foldl' :: (a -> v -> a) -> a -> HashMap k v -> a
foldl' f = foldlWithKey' (\ z _ v -> f z v)
Expand All @@ -1539,7 +1548,7 @@ foldl' f = foldlWithKey' (\ z _ v -> f z v)
-- | /O(n)/ Reduce this map by applying a binary operator to all
-- elements, using the given starting value (typically the
-- left-identity of the operator). Each application of the operator
-- is evaluated before using the result in the next application.
-- is evaluated before using the result in the next application.
-- This function is strict in the starting value.
foldlWithKey' :: (a -> k -> v -> a) -> a -> HashMap k v -> a
foldlWithKey' f = go
Expand Down
10 changes: 10 additions & 0 deletions Data/HashSet/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ instance Ord1 HashSet where
instance Foldable.Foldable HashSet where
foldr = Data.HashSet.Base.foldr
{-# INLINE foldr #-}
foldl' = Data.HashSet.Base.foldl'
{-# INLINE foldl' #-}
#if MIN_VERSION_base(4,8,0)
toList = Data.HashSet.Base.toList
{-# INLINE toList #-}
null = Data.HashSet.Base.null
{-# INLINE null #-}
length = Data.HashSet.Base.size
{-# INLINE length #-}
#endif

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