foldl 1.0.3 → 1.0.4
raw patch · 2 files changed
+40/−5 lines, 2 filesdep +containersdep ~transformers
Dependencies added: containers
Dependency ranges changed: transformers
Files
- foldl.cabal +4/−3
- src/Control/Foldl.hs +36/−2
foldl.cabal view
@@ -1,5 +1,5 @@ Name: foldl-Version: 1.0.3+Version: 1.0.4 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -25,8 +25,9 @@ bytestring >= 0.9.2.1 && < 0.11, primitive < 0.6 , text >= 0.11.2.0 && < 1.2 ,- transformers >= 0.2.0.0 && < 0.4 ,- vector >= 0.7 && < 0.11+ transformers >= 0.2.0.0 && < 0.5 ,+ vector >= 0.7 && < 0.11,+ containers < 0.6 Exposed-Modules: Control.Foldl, Control.Foldl.ByteString,
src/Control/Foldl.hs view
@@ -66,6 +66,9 @@ -- * Container folds , list+ , nub+ , eqNub+ , set , vector -- * Utilities@@ -94,6 +97,8 @@ import Data.Vector.Generic (Vector) import qualified Data.Vector.Generic as V import qualified Data.Vector.Generic.Mutable as M+import qualified Data.List as List+import qualified Data.Set as Set import Prelude hiding ( head , last@@ -286,7 +291,7 @@ where step x a = Just' (case x of Nothing' -> a- Just' a' -> max a a')+ Just' a' -> max a' a) {-# INLINABLE maximum #-} -- | Computes the minimum element@@ -295,7 +300,7 @@ where step x a = Just' (case x of Nothing' -> a- Just' a' -> min a a')+ Just' a' -> min a' a) {-# INLINABLE minimum #-} {-| @(elem a)@ returns 'True' if the container has an element equal to @a@,@@ -372,6 +377,35 @@ list :: Fold a [a] list = Fold (\x a -> x . (a:)) id ($ []) {-# INLINABLE list #-}++{-| /O(n log n)/. Fold values into a list with duplicates removed, while+ preserving their first occurrences+-}+nub :: Ord a => Fold a [a]+nub = Fold step (Pair Set.empty id) fin+ where+ step (Pair s r) a = if Set.member a s+ then Pair s r+ else Pair (Set.insert a s) (r . (a :))+ fin (Pair _ r) = r []+{-# INLINABLE nub #-}++{-| /O(n^2)/. Fold values into a list with duplicates removed, while preserving+ their first occurrences+-}+eqNub :: Eq a => Fold a [a]+eqNub = Fold step (Pair [] id) fin+ where+ step (Pair known r) a = if List.elem a known+ then Pair known r+ else Pair (a : known) (r . (a :))+ fin (Pair _ r) = r []+{-# INLINABLE eqNub #-}++-- | Fold values into a set+set :: (Ord a) => Fold a (Set.Set a)+set = Fold (flip Set.insert) Set.empty id+{-# INLINABLE set #-} maxChunkSize :: Int maxChunkSize = 8 * 1024 * 1024