packages feed

deferred-folds 0.2.1 → 0.2.2

raw patch · 3 files changed

+79/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ DeferredFolds.FoldlMView: FoldlMView :: (forall m output. Monad m => (output -> input -> m output) -> output -> m output) -> FoldlMView input
+ DeferredFolds.FoldlMView: fold :: Fold input output -> FoldlMView input -> output
+ DeferredFolds.FoldlMView: foldable :: Foldable foldable => foldable a -> FoldlMView a
+ DeferredFolds.FoldlMView: foldl' :: (output -> input -> output) -> output -> FoldlMView input -> output
+ DeferredFolds.FoldlMView: instance Data.Semigroup.Semigroup (DeferredFolds.FoldlMView.FoldlMView a)
+ DeferredFolds.FoldlMView: instance GHC.Base.Alternative DeferredFolds.FoldlMView.FoldlMView
+ DeferredFolds.FoldlMView: instance GHC.Base.Applicative DeferredFolds.FoldlMView.FoldlMView
+ DeferredFolds.FoldlMView: instance GHC.Base.Functor DeferredFolds.FoldlMView.FoldlMView
+ DeferredFolds.FoldlMView: instance GHC.Base.Monad DeferredFolds.FoldlMView.FoldlMView
+ DeferredFolds.FoldlMView: instance GHC.Base.MonadPlus DeferredFolds.FoldlMView.FoldlMView
+ DeferredFolds.FoldlMView: instance GHC.Base.Monoid (DeferredFolds.FoldlMView.FoldlMView a)
+ DeferredFolds.FoldlMView: intsInRange :: Int -> Int -> FoldlMView Int
+ DeferredFolds.FoldlMView: newtype FoldlMView input

Files

deferred-folds.cabal view
@@ -1,7 +1,7 @@ name:   deferred-folds version:-  0.2.1+  0.2.2 category:   Folding synopsis:@@ -40,6 +40,7 @@     Haskell2010   exposed-modules:     DeferredFolds.FoldlView+    DeferredFolds.FoldlMView   other-modules:     DeferredFolds.Prelude   build-depends:
+ library/DeferredFolds/FoldlMView.hs view
@@ -0,0 +1,76 @@+module DeferredFolds.FoldlMView+where++import DeferredFolds.Prelude hiding (foldl')+import qualified DeferredFolds.Prelude as A+++newtype FoldlMView input =+  FoldlMView (forall m output. Monad m => (output -> input -> m output) -> output -> m output)++deriving instance Functor FoldlMView++instance Applicative FoldlMView where+  pure x =+    FoldlMView (\ step init -> step init x)+  (<*>) = ap++instance Alternative FoldlMView where+  empty =+    FoldlMView (const return)+  {-# INLINE (<|>) #-}+  (<|>) (FoldlMView left) (FoldlMView right) =+    FoldlMView (\ step init -> left step init >>= right step)++instance Monad FoldlMView where+  return = pure+  (>>=) (FoldlMView left) rightK =+    FoldlMView $ \ step init ->+    let+      newStep output x =+        case rightK x of+          FoldlMView right ->+            right step output+      in left newStep init++instance MonadPlus FoldlMView where+  mzero = empty+  mplus = (<|>)++instance Semigroup (FoldlMView a) where+  (<>) = (<|>)++instance Monoid (FoldlMView a) where+  mempty = empty+  mappend = (<>)++{-| Perform a strict left fold -}+{-# INLINE foldl' #-}+foldl' :: (output -> input -> output) -> output -> FoldlMView input -> output+foldl' step init (FoldlMView run) =+  runIdentity (run identityStep init)+  where+    identityStep state input = return (step state input)++{-| Apply a Gonzalez fold -}+{-# INLINE fold #-}+fold :: Fold input output -> FoldlMView input -> output+fold (Fold step init extract) = extract . foldl' step init++{-| Construct from any foldable -}+{-# INLINE foldable #-}+foldable :: Foldable foldable => foldable a -> FoldlMView a+foldable foldable = FoldlMView (\ step init -> A.foldlM step init foldable)++{-| Ints in the specified inclusive range -}+intsInRange :: Int -> Int -> FoldlMView Int+intsInRange from to =+  FoldlMView $ \ step init ->+  let+    loop !state int =+      if int <= to+        then do+          newState <- step state int+          loop newState (succ int)+        else return state+    in loop init from
library/DeferredFolds/Prelude.hs view
@@ -12,6 +12,7 @@ import Data.Monoid as Exports hiding ((<>), First(..), Last(..)) import Data.Semigroup as Exports import Data.Foldable as Exports+import Data.Functor.Identity as Exports import Data.Traversable as Exports import Control.Applicative as Exports import Control.Monad as Exports