packages feed

foldl 1.4.2 → 1.4.3

raw patch · 4 files changed

+70/−6 lines, 4 filesdep ~mwc-randomPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: mwc-random

API changes (from Hackage documentation)

+ Control.Scanl: instance GHC.Base.Applicative (Control.Scanl.ReverseState s)
+ Control.Scanl: instance GHC.Base.Functor (Control.Scanl.ReverseState s)
+ Control.Scanl: scanr :: Traversable t => Scan a b -> t a -> t b

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+1.4.3++* Add `Control.Scanl.scanr`+* Increase upper bound on `mwc-random`+ 1.4.2  * Add `Semigroupoid` instance for `Fold`
README.md view
@@ -1,4 +1,4 @@-# `foldl` v1.4.2+# `foldl` v1.4.3  Use this `foldl` library when you want to compute multiple folds over a collection in one pass over the data without space leaks.
foldl.cabal view
@@ -1,5 +1,5 @@ Name: foldl-Version: 1.4.2+Version: 1.4.3 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -26,7 +26,7 @@     Build-Depends:         base         >= 4.5      && < 5   ,         bytestring   >= 0.9.2.1  && < 0.11,-        mwc-random   >= 0.13.1.0 && < 0.14,+        mwc-random   >= 0.13.1.0 && < 0.15,         primitive                   < 0.7 ,         text         >= 0.11.2.0 && < 1.3 ,         transformers >= 0.2.0.0  && < 0.6 ,
src/Control/Scanl.hs view
@@ -5,10 +5,11 @@  >>> import qualified Control.Scanl as SL -    Use 'scan' to apply a 'Fold' to a list:+    Use 'scan' to apply a 'Fold' to a list (or other 'Traversable' structures) from left to right,+    and 'scanr' to do so from right to left. -} -{-# LANGUAGE BangPatterns              #-}+{-# LANGUAGE CPP                       #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts          #-} {-# LANGUAGE RankNTypes                #-}@@ -22,6 +23,7 @@     -- * Scanning     , scan     , scanM+    , scanr      , prescan     , postscan@@ -54,8 +56,12 @@ import Data.Semigroup (Semigroup(..)) import Data.Traversable import Data.Tuple (swap)-import Prelude hiding ((.), id)+import Prelude hiding ((.), id, scanr) +#if MIN_VERSION_base(4, 7, 0)+import Data.Coerce+#endif+ --import qualified Control.Foldl as L  {-| Efficient representation of a left map-with-accumulator that preserves the@@ -365,6 +371,12 @@ scan (Scan step begin) as = fst $ runState (traverse step as) begin {-# INLINE scan #-} +-- | Like 'scan' but start scanning from the right+scanr :: Traversable t => Scan a b -> t a -> t b+scanr (Scan step begin) as =+  fst (runReverseState (traverse (ReverseState #. runState . step) as) begin)+{-# INLINE scanr #-}+ -- | Like 'scan' but monadic scanM :: (Traversable t, Monad m) => ScanM m a b -> t a -> m (t b) scanM (ScanM step begin) as = fmap fst $ runStateT (traverse step as) =<< begin@@ -490,3 +502,50 @@ premapM :: Monad m => (a -> m b) -> ScanM m b r -> ScanM m a r premapM f (ScanM step begin) = ScanM (step <=< lift . f) begin {-# INLINABLE premapM #-}+++-- Internal helpers (not exported)+newtype ReverseState s a = ReverseState+  { runReverseState :: s -> (a, s)+  }++instance Functor (ReverseState s) where+  fmap f (ReverseState m) =+    ReverseState $ \s ->+      let (v, s') = m s+      in (f v, s')+  {-# INLINE fmap #-}++instance Applicative (ReverseState s) where+  pure = ReverseState #. (,)+  {-# INLINE pure #-}++  mf <*> mx =+    ReverseState $ \s ->+      let (f, s2) = runReverseState mf s1+          (x, s1) = runReverseState mx s+      in (f x, s2)+  {-# INLINE (<*>) #-}++#if MIN_VERSION_base(4, 10, 0)+  -- 'liftA2' was moved to the 'Applicative' class in base 4.10.0.0+  liftA2 f mx my =+    ReverseState $ \s ->+      let (x, s2) = runReverseState mx s1+          (y, s1) = runReverseState my s+      in (f x y, s2)+  {-# INLINE liftA2 #-}+#endif+++#if MIN_VERSION_base(4, 7, 0)+-- | This is same as normal function composition, except slightly more efficient. The same trick is used in base <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Data.Functor.Utils.html#%23.> and lens <http://hackage.haskell.org/package/lens-4.17/docs/Control-Lens-Internal-Coerce.html#v:-35-..>+(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)+(#.) _ = coerce+#else+(#.) :: (b -> c) -> (a -> b) -> (a -> c)+(#.) = (.)+#endif++infixr 9 #.+{-# INLINE (#.) #-}