deferred-folds 0.6.11 → 0.6.12
raw patch · 3 files changed
+50/−38 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ DeferredFolds.Unfold: primArrayWithIndices :: (Prim prim) => PrimArray prim -> Unfold (Int, prim)
+ DeferredFolds.UnfoldM: primArrayWithIndices :: (Monad m, Prim prim) => PrimArray prim -> UnfoldM m (Int, prim)
Files
- deferred-folds.cabal +18/−36
- library/DeferredFolds/Unfold.hs +16/−1
- library/DeferredFolds/UnfoldM.hs +16/−1
deferred-folds.cabal view
@@ -1,43 +1,25 @@-name:- deferred-folds-version:- 0.6.11-category:- Folding-synopsis:- Abstractions over deferred folds-homepage:- https://github.com/metrix-ai/deferred-folds -bug-reports:- https://github.com/metrix-ai/deferred-folds/issues -author:- Nikita Volkov <nikita.y.volkov@mail.ru>-maintainer:- Metrix.AI Ninjas <ninjas@metrix.ai>-copyright:- (c) 2018, Metrix.AI-license:- MIT-license-file:- LICENSE-build-type:- Simple-cabal-version:- >=1.10+name: deferred-folds+version: 0.6.12+category: Folding+synopsis: Abstractions over deferred folds+homepage: https://github.com/metrix-ai/deferred-folds+bug-reports: https://github.com/metrix-ai/deferred-folds/issues+author: Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer: Metrix.AI Tech Team <tech@metrix.ai>+copyright: (c) 2018, Metrix.AI+license: MIT+license-file: LICENSE+build-type: Simple+cabal-version: >=1.10 source-repository head- type:- git- location:- git://github.com/metrix-ai/deferred-folds.git+ type: git+ location: git://github.com/metrix-ai/deferred-folds.git library- hs-source-dirs:- library- default-extensions:- Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, PatternSynonyms, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples- default-language:- Haskell2010+ hs-source-dirs: library+ default-extensions: Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, PatternSynonyms, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+ default-language: Haskell2010 exposed-modules: DeferredFolds.Unfold DeferredFolds.UnfoldM
library/DeferredFolds/Unfold.hs view
@@ -152,24 +152,39 @@ else state in loop init from +{-| Associations of a map -} {-# INLINE map #-} map :: Map key value -> Unfold (key, value) map map = Unfold (\ step init -> C.foldlWithKey' (\ state key value -> step state (key, value)) init map) +{-| Associations of an intmap -} {-# INLINE intMap #-} intMap :: IntMap value -> Unfold (Int, value) intMap intMap = Unfold (\ step init -> D.foldlWithKey' (\ state key value -> step state (key, value)) init intMap) +{-| Bytes of a bytestring -} {-# INLINE byteStringBytes #-} byteStringBytes :: ByteString -> Unfold Word8 byteStringBytes bs = Unfold (\ step init -> ByteString.foldl' step init bs) +{-| Bytes of a short bytestring -} {-# INLINE shortByteStringBytes #-} shortByteStringBytes :: ShortByteString -> Unfold Word8 shortByteStringBytes (ShortByteString.SBS ba#) = primArray (PrimArray ba#) +{-| Elements of a prim array -} {-# INLINE primArray #-} primArray :: (Prim prim) => PrimArray prim -> Unfold prim-primArray ba = Unfold $ \f z -> foldlPrimArray' f z ba+primArray ba = Unfold $ \ f z -> foldlPrimArray' f z ba++{-| Elements of a prim array coming paired with indices -}+{-# INLINE primArrayWithIndices #-}+primArrayWithIndices :: (Prim prim) => PrimArray prim -> Unfold (Int, prim)+primArrayWithIndices pa = Unfold $ \ step state -> let+ !size = sizeofPrimArray pa+ iterate index !state = if index < size+ then iterate (succ index) (step state (index, indexPrimArray pa index))+ else state+ in iterate 0 state
library/DeferredFolds/UnfoldM.hs view
@@ -157,6 +157,7 @@ hoist trans1 trans2 (UnfoldM unfold) = UnfoldM $ \ step init -> trans1 (unfold (\ a b -> trans2 (step a b)) init) +{-| Bytes of a bytestring -} {-# INLINABLE byteStringBytes #-} byteStringBytes :: ByteString -> UnfoldM IO Word8 byteStringBytes (ByteString.PS fp off len) =@@ -172,10 +173,24 @@ iterate newState (plusPtr ptr 1) in iterate init (plusPtr ptr off) +{-| Bytes of a short bytestring -} {-# INLINE shortByteStringBytes #-} shortByteStringBytes :: Monad m => ShortByteString -> UnfoldM m Word8 shortByteStringBytes (ShortByteString.SBS ba#) = primArray (PrimArray ba#) +{-| Elements of a prim array -} {-# INLINE primArray #-} primArray :: (Monad m, Prim prim) => PrimArray prim -> UnfoldM m prim-primArray ba = UnfoldM $ \f z -> foldlPrimArrayM' f z ba+primArray pa = UnfoldM $ \ f z -> foldlPrimArrayM' f z pa++{-| Elements of a prim array coming paired with indices -}+{-# INLINE primArrayWithIndices #-}+primArrayWithIndices :: (Monad m, Prim prim) => PrimArray prim -> UnfoldM m (Int, prim)+primArrayWithIndices pa = UnfoldM $ \ step state -> let+ !size = sizeofPrimArray pa+ iterate index !state = if index < size+ then do+ newState <- step state (index, indexPrimArray pa index)+ iterate (succ index) newState+ else return state+ in iterate 0 state