packages feed

foldl 1.0.6 → 1.0.7

raw patch · 4 files changed

+205/−11 lines, 4 filesdep ~basedep ~text

Dependency ranges changed: base, text

Files

foldl.cabal view
@@ -1,5 +1,5 @@ Name: foldl-Version: 1.0.6+Version: 1.0.7 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -24,7 +24,7 @@         base         >= 4        && < 5   ,         bytestring   >= 0.9.2.1  && < 0.11,         primitive                   < 0.6 ,-        text         >= 0.11.2.0 && < 1.2 ,+        text         >= 0.11.2.0 && < 1.3 ,         transformers >= 0.2.0.0  && < 0.5 ,         vector       >= 0.7      && < 0.11,         containers                  < 0.6
src/Control/Foldl.hs view
@@ -138,6 +138,7 @@ instance Applicative (Fold a) where     pure b    = Fold (\() _ -> ()) () (\() -> b)     {-# INLINABLE pure #-}+     (Fold stepL beginL doneL) <*> (Fold stepR beginR doneR) =         let step (Pair xL xR) a = Pair (stepL xL a) (stepR xR a)             begin = Pair beginL beginR@@ -148,9 +149,97 @@ instance Monoid b => Monoid (Fold a b) where     mempty = pure mempty     {-# INLINABLE mempty #-}+     mappend = liftA2 mappend     {-# INLINABLE mappend #-} +instance Num b => Num (Fold a b) where+    fromInteger = pure . fromInteger+    {-# INLINABLE fromInteger #-}++    negate = fmap negate+    {-# INLINABLE negate #-}++    abs = fmap abs+    {-# INLINABLE abs #-}++    signum = fmap signum+    {-# INLINABLE signum #-}++    (+) = liftA2 (+)+    {-# INLINABLE (+) #-}++    (*) = liftA2 (*)+    {-# INLINABLE (*) #-}++    (-) = liftA2 (-)+    {-# INLINABLE (-) #-}++instance Fractional b => Fractional (Fold a b) where+    fromRational = pure . fromRational+    {-# INLINABLE fromRational #-}++    recip = fmap recip+    {-# INLINABLE recip #-}++    (/) = liftA2 (/)+    {-# INLINABLE (/) #-}++instance Floating b => Floating (Fold a b) where+    pi = pure pi+    {-# INLINABLE pi #-}++    exp = fmap exp+    {-# INLINABLE exp #-}++    sqrt = fmap sqrt+    {-# INLINABLE sqrt #-}++    log = fmap log+    {-# INLINABLE log #-}++    sin = fmap sin+    {-# INLINABLE sin #-}++    tan = fmap tan+    {-# INLINABLE tan #-}++    cos = fmap cos+    {-# INLINABLE cos #-}++    asin = fmap sin+    {-# INLINABLE asin #-}++    atan = fmap atan+    {-# INLINABLE atan #-}++    acos = fmap acos+    {-# INLINABLE acos #-}++    sinh = fmap sinh+    {-# INLINABLE sinh #-}++    tanh = fmap tanh+    {-# INLINABLE tanh #-}++    cosh = fmap cosh+    {-# INLINABLE cosh #-}++    asinh = fmap asinh+    {-# INLINABLE asinh #-}++    atanh = fmap atanh+    {-# INLINABLE atanh #-}++    acosh = fmap acosh+    {-# INLINABLE acosh #-}++    (**) = liftA2 (**)+    {-# INLINABLE (**) #-}++    logBase = liftA2 logBase+    {-# INLINABLE logBase #-}+ -- | Like 'Fold', but monadic data FoldM m a b = forall x . FoldM (x -> a -> m x) (m x) (x -> m b) @@ -165,6 +254,7 @@ instance Monad m => Applicative (FoldM m a) where     pure b = FoldM (\() _ -> return ()) (return ()) (\() -> return b)     {-# INLINABLE pure #-}+     (FoldM stepL beginL doneL) <*> (FoldM stepR beginR doneR) =         let step (Pair xL xR) a = do                 xL' <- stepL xL a@@ -184,9 +274,97 @@ instance (Monoid b, Monad m) => Monoid (FoldM m a b) where     mempty = pure mempty     {-# INLINABLE mempty #-}+     mappend = liftA2 mappend     {-# INLINABLE mappend #-} +instance (Monad m, Num b) => Num (FoldM m a b) where+    fromInteger = pure . fromInteger+    {-# INLINABLE fromInteger #-}++    negate = fmap negate+    {-# INLINABLE negate #-}++    abs = fmap abs+    {-# INLINABLE abs #-}++    signum = fmap signum+    {-# INLINABLE signum #-}++    (+) = liftA2 (+)+    {-# INLINABLE (+) #-}++    (*) = liftA2 (*)+    {-# INLINABLE (*) #-}++    (-) = liftA2 (-)+    {-# INLINABLE (-) #-}++instance (Monad m, Fractional b) => Fractional (FoldM m a b) where+    fromRational = pure . fromRational+    {-# INLINABLE fromRational #-}++    recip = fmap recip+    {-# INLINABLE recip #-}++    (/) = liftA2 (/)+    {-# INLINABLE (/) #-}++instance (Monad m, Floating b) => Floating (FoldM m a b) where+    pi = pure pi+    {-# INLINABLE pi #-}++    exp = fmap exp+    {-# INLINABLE exp #-}++    sqrt = fmap sqrt+    {-# INLINABLE sqrt #-}++    log = fmap log+    {-# INLINABLE log #-}++    sin = fmap sin+    {-# INLINABLE sin #-}++    tan = fmap tan+    {-# INLINABLE tan #-}++    cos = fmap cos+    {-# INLINABLE cos #-}++    asin = fmap sin+    {-# INLINABLE asin #-}++    atan = fmap atan+    {-# INLINABLE atan #-}++    acos = fmap acos+    {-# INLINABLE acos #-}++    sinh = fmap sinh+    {-# INLINABLE sinh #-}++    tanh = fmap tanh+    {-# INLINABLE tanh #-}++    cosh = fmap cosh+    {-# INLINABLE cosh #-}++    asinh = fmap asinh+    {-# INLINABLE asinh #-}++    atanh = fmap atanh+    {-# INLINABLE atanh #-}++    acosh = fmap acosh+    {-# INLINABLE acosh #-}++    (**) = liftA2 (**)+    {-# INLINABLE (**) #-}++    logBase = liftA2 logBase+    {-# INLINABLE logBase #-}+ -- | Apply a strict left 'Fold' to a 'Foldable' container fold :: Foldable f => Fold a b -> f a -> b fold (Fold step begin done) as = F.foldr cons done as begin@@ -415,7 +593,7 @@ {-# INLINABLE eqNub #-}  -- | Fold values into a set-set :: (Ord a) => Fold a (Set.Set a)+set :: Ord a => Fold a (Set.Set a) set = Fold (flip Set.insert) Set.empty id {-# INLINABLE set #-} 
src/Control/Foldl/ByteString.hs view
@@ -19,6 +19,7 @@     , index     , elemIndex     , findIndex+    , count      -- * Re-exports     -- $reexports@@ -78,7 +79,7 @@ {-# INLINABLE null #-}  -- | Return the length of the byte stream in bytes-length :: (Num n) => Fold ByteString n+length :: Num n => Fold ByteString n length = L.Fold (\n bs -> n + fromIntegral (B.length bs)) 0 id {-# INLINABLE length #-} @@ -148,7 +149,7 @@ {-| @(index n)@ returns the @n@th byte of the byte stream, or 'Nothing' if the     stream has an insufficient number of bytes -}-index :: (Integral n) => n -> Fold ByteString (Maybe Word8)+index :: Integral n => n -> Fold ByteString (Maybe Word8) index i = L.Fold step (Left' (fromIntegral i)) hush   where     step x bs = case x of@@ -163,14 +164,14 @@ {-| @(elemIndex w8)@ returns the index of the first byte that equals @w8@, or     'Nothing' if no byte matches -}-elemIndex :: (Num n) => Word8 -> Fold ByteString (Maybe n)+elemIndex :: Num n => Word8 -> Fold ByteString (Maybe n) elemIndex w8 = findIndex (w8 ==) {-# INLINABLE elemIndex #-}  {-| @(findIndex predicate)@ returns the index of the first byte that satisfies     the predicate, or 'Nothing' if no byte satisfies the predicate -}-findIndex :: (Num n) => (Word8 -> Bool) -> Fold ByteString (Maybe n)+findIndex :: Num n => (Word8 -> Bool) -> Fold ByteString (Maybe n) findIndex predicate = L.Fold step (Left' 0) hush   where     step x bs = case x of@@ -179,6 +180,13 @@             Just n  -> Right' (m + fromIntegral n)         _       -> x {-# INLINABLE findIndex #-}++-- | @count w8@ returns the number of times @w8@ appears+count :: Num n => Word8 -> Fold ByteString n+count w8 = L.Fold step 0 id+  where+    step n bs = n + fromIntegral (B.count w8 bs)+{-# INLINABLE count #-}  {- $reexports 
src/Control/Foldl/Text.hs view
@@ -19,6 +19,7 @@     , index     , elemIndex     , findIndex+    , count      -- * Re-exports     -- $reexports@@ -75,7 +76,7 @@ {-# INLINABLE null #-}  -- | Return the length of the text stream in characters-length :: (Num n) => Fold Text n+length :: Num n => Fold Text n length = L.Fold (\n txt -> n + fromIntegral (T.length txt)) 0 id {-# INLINABLE length #-} @@ -145,7 +146,7 @@ {-| @(index n)@ returns the @n@th character of the text stream, or 'Nothing' if     the stream has an insufficient number of characters -}-index :: (Integral n) => n -> Fold Text (Maybe Char)+index :: Integral n => n -> Fold Text (Maybe Char) index i = L.Fold step (Left' (fromIntegral i)) hush   where     step x txt = case x of@@ -160,7 +161,7 @@ {-| @(elemIndex c)@ returns the index of the first character that equals @c@,     or 'Nothing' if no character matches -}-elemIndex :: (Num n) => Char -> Fold Text (Maybe n)+elemIndex :: Num n => Char -> Fold Text (Maybe n) elemIndex c = findIndex (c ==) {-# INLINABLE elemIndex #-} @@ -168,7 +169,7 @@     satisfies the predicate, or 'Nothing' if no character satisfies the     predicate -}-findIndex :: (Num n) => (Char -> Bool) -> Fold Text (Maybe n)+findIndex :: Num n => (Char -> Bool) -> Fold Text (Maybe n) findIndex predicate = L.Fold step (Left' 0) hush   where     step x txt = case x of@@ -177,6 +178,13 @@             Just n  -> Right' (m + fromIntegral n)         _       -> x {-# INLINABLE findIndex #-}++-- | @(count c)@ returns the number of times @c@ appears+count :: Num n => Char -> Fold Text n+count c = L.Fold step 0 id+  where+    step n txt = n + fromIntegral (T.count (T.singleton c) txt)+{-# INLINABLE count #-}  {- $reexports     "Control.Foldl" re-exports the 'Fold' type