packages feed

deferred-folds 0.6.8 → 0.6.9

raw patch · 4 files changed

+28/−1 lines, 4 filesdep +bytestringPVP ok

version bump matches the API change (PVP)

Dependencies added: bytestring

API changes (from Hackage documentation)

+ DeferredFolds.Unfold: byteStringBytes :: ByteString -> Unfold Word8
+ DeferredFolds.UnfoldM: byteStringBytes :: ByteString -> UnfoldM IO Word8

Files

deferred-folds.cabal view
@@ -1,7 +1,7 @@ name:   deferred-folds version:-  0.6.8+  0.6.9 category:   Folding synopsis:@@ -45,6 +45,7 @@     DeferredFolds.Prelude   build-depends:     base >=4.7 && <5,+    bytestring >=0.10 && <0.11,     containers >=0.5 && <0.6,     foldl >=1 && <2,     transformers >=0.5 && <0.6
library/DeferredFolds/Prelude.hs view
@@ -86,3 +86,7 @@ -- transformers ------------------------- import Control.Monad.Trans.Class as Exports++-- bytestring+-------------------------+import Data.ByteString as Exports (ByteString)
library/DeferredFolds/Unfold.hs view
@@ -6,6 +6,7 @@ import qualified DeferredFolds.UnfoldM as B import qualified Data.Map.Strict as C import qualified Data.IntMap.Strict as D+import qualified Data.ByteString as ByteString   {-|@@ -153,3 +154,7 @@ intMap :: IntMap value -> Unfold (Int, value) intMap intMap =   Unfold (\ step init -> D.foldlWithKey' (\ state key value -> step state (key, value)) init intMap)++{-# INLINE byteStringBytes #-}+byteStringBytes :: ByteString -> Unfold Word8+byteStringBytes bs = Unfold (\ step init -> ByteString.foldl' step init bs)
library/DeferredFolds/UnfoldM.hs view
@@ -3,6 +3,8 @@  import DeferredFolds.Prelude hiding (mapM_) import qualified DeferredFolds.Prelude as A+import qualified Data.ByteString as ByteString+import qualified Data.ByteString.Internal as ByteString   {-|@@ -149,3 +151,18 @@ hoist :: (forall a. m a -> n a) -> (forall a. n a -> m a) -> UnfoldM m a -> UnfoldM n a hoist trans1 trans2 (UnfoldM unfold) = UnfoldM $ \ step init ->    trans1 (unfold (\ a b -> trans2 (step a b)) init)++{-# INLINE byteStringBytes #-}+byteStringBytes :: ByteString -> UnfoldM IO Word8+byteStringBytes (ByteString.PS fp off len) =+  UnfoldM $ \ step init ->+  withForeignPtr fp $ \ ptr ->+  let+    endPtr = plusPtr ptr (off + len)+    iterate !state !ptr = if ptr == endPtr+      then return state+      else do+        x <- peek ptr+        newState <- step state x+        iterate newState (plusPtr ptr 1)+    in iterate init (plusPtr ptr off)