diff options
author | GabrielGonzalez <> | 2017-01-08 13:23:00 (GMT) |
---|---|---|
committer | hdiff <hdiff@hdiff.luite.com> | 2017-01-08 13:23:00 (GMT) |
commit | 16637a633ab039c4f489824fc0e102eee185e688 (patch) | |
tree | 2539a523f4a6ef4cd8cb2db0f73c4344ce45291c | |
parent | 4adebacd8fc20d2b376d58c5cd7ccb111fefbcbf (diff) |
version 1.2.31.2.3
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | foldl.cabal | 4 | ||||
-rw-r--r-- | src/Control/Foldl.hs | 16 |
3 files changed, 19 insertions, 3 deletions
@@ -1,4 +1,4 @@ -# `foldl` v1.2.2 +# `foldl` v1.2.3 Use this `foldl` library when you want to compute multiple folds over a collection in one pass over the data without space leaks. diff --git a/foldl.cabal b/foldl.cabal index 43b4433..8d83695 100644 --- a/foldl.cabal +++ b/foldl.cabal @@ -1,5 +1,5 @@ Name: foldl -Version: 1.2.2 +Version: 1.2.3 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3 @@ -31,7 +31,7 @@ Library primitive < 0.7 , text >= 0.11.2.0 && < 1.3 , transformers >= 0.2.0.0 && < 0.6 , - vector >= 0.7 && < 0.12, + vector >= 0.7 && < 0.13, containers < 0.6 , contravariant < 1.5 , profunctors < 5.3 , diff --git a/src/Control/Foldl.hs b/src/Control/Foldl.hs index f0cd7c9..b420ff0 100644 --- a/src/Control/Foldl.hs +++ b/src/Control/Foldl.hs @@ -76,6 +76,7 @@ module Control.Foldl ( , notElem , find , index + , lookup , elemIndex , findIndex , random @@ -154,6 +155,7 @@ import Prelude hiding , minimum , elem , notElem + , lookup ) import qualified Data.Foldable as F @@ -672,6 +674,20 @@ findIndex predicate = Fold step (Left' 0) hush _ -> x {-# INLINABLE findIndex #-} + +{-| @(lookup a)@ returns the element paired with the first matching item, or + 'Nothing' if none matches +-} +lookup :: Eq a => a -> Fold (a,b) (Maybe b) +lookup a0 = Fold step Nothing' lazy + where + step x (a,b) = case x of + Nothing' -> if a == a0 + then Just' b + else Nothing' + _ -> x +{-# INLINABLE lookup #-} + data Pair3 a b c = Pair3 !a !b !c -- | Pick a random element, using reservoir sampling |