Skip to content

Commit

Permalink
Added the latest fold
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriella439 committed Jun 7, 2014
1 parent ac0d4af commit 591c64a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Control/Foldl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module Control.Foldl (
, foldMap
, head
, last
, latest
, null
, length
, and
Expand Down Expand Up @@ -236,6 +237,13 @@ last :: Fold a (Maybe a)
last = Fold (\_ -> Just') Nothing' lazy
{-# INLINABLE last #-}

{-| Get the last element of a container or return a default value if the container
is empty
-}
latest :: a -> Fold a a
latest a = Fold (\_ a' -> a') a id
{-# INLINABLE latest #-}

-- | Returns 'True' if the container is empty, 'False' otherwise
null :: Fold a Bool
null = Fold (\_ _ -> False) True id
Expand Down

0 comments on commit 591c64a

Please sign in to comment.