primitive-extras 0.6.7 → 0.7
raw patch · 10 files changed
+66/−66 lines, 10 filesdep ~deferred-folds
Dependency ranges changed: deferred-folds
Files
- library/PrimitiveExtras/Bitmap.hs +11/−11
- library/PrimitiveExtras/Prelude.hs +2/−2
- library/PrimitiveExtras/PrimArray.hs +4/−4
- library/PrimitiveExtras/PrimMultiArray.hs +22/−22
- library/PrimitiveExtras/SmallArray.hs +4/−4
- library/PrimitiveExtras/SparseSmallArray.hs +11/−11
- primitive-extras.cabal +2/−2
- test/Main.hs +1/−1
- test/Main/Gens.hs +2/−2
- test/Main/Transaction.hs +7/−7
library/PrimitiveExtras/Bitmap.hs view
@@ -16,15 +16,15 @@ populatedIndicesList, int, allBitsList,- allBitsUnfold,- populatedBitsUnfold,- indicesAmongstPopulatedBitsUnfold,+ allBitsUnfoldl,+ populatedBitsUnfoldl,+ indicesAmongstPopulatedBitsUnfoldl, ) where import PrimitiveExtras.Prelude hiding (traverse_, insert, null, empty) import PrimitiveExtras.Types-import qualified DeferredFolds.Unfold as Unfold+import qualified DeferredFolds.Unfoldl as Unfoldl deriving instance Eq Bitmap@@ -105,12 +105,12 @@ int :: Bitmap -> Int int (Bitmap int) = int -{-# NOINLINE allBitsUnfold #-}-allBitsUnfold :: Unfold Int-allBitsUnfold = Unfold.intsInRange 0 maxBit+{-# NOINLINE allBitsUnfoldl #-}+allBitsUnfoldl :: Unfoldl Int+allBitsUnfoldl = Unfoldl.intsInRange 0 maxBit -populatedBitsUnfold :: Bitmap -> Unfold Int-populatedBitsUnfold bitmap = Unfold.filter (flip isPopulated bitmap) allBitsUnfold+populatedBitsUnfoldl :: Bitmap -> Unfoldl Int+populatedBitsUnfoldl bitmap = Unfoldl.filter (flip isPopulated bitmap) allBitsUnfoldl -indicesAmongstPopulatedBitsUnfold :: Bitmap -> Unfold Int-indicesAmongstPopulatedBitsUnfold bitmap = Unfold.intsInRange 0 (pred (population bitmap))+indicesAmongstPopulatedBitsUnfoldl :: Bitmap -> Unfoldl Int+indicesAmongstPopulatedBitsUnfoldl bitmap = Unfoldl.intsInRange 0 (pred (population bitmap))
library/PrimitiveExtras/Prelude.hs view
@@ -81,8 +81,8 @@ -- deferred-folds --------------------------import DeferredFolds.Unfold as Exports (Unfold(..))-import DeferredFolds.UnfoldM as Exports (UnfoldM(..))+import DeferredFolds.Unfoldl as Exports (Unfoldl(..))+import DeferredFolds.UnfoldlM as Exports (UnfoldlM(..)) -- foldl -------------------------
library/PrimitiveExtras/PrimArray.hs view
@@ -72,11 +72,11 @@ else return () in iterate from -toElementsUnfold :: Prim prim => PrimArray prim -> Unfold prim-toElementsUnfold ba = Unfold $ \f z -> foldlPrimArray' f z ba+toElementsUnfoldl :: Prim prim => PrimArray prim -> Unfoldl prim+toElementsUnfoldl ba = Unfoldl $ \f z -> foldlPrimArray' f z ba -toElementsUnfoldM :: (Monad m, Prim prim) => PrimArray prim -> UnfoldM m prim-toElementsUnfoldM ba = UnfoldM $ \f z -> foldlPrimArrayM' f z ba+toElementsUnfoldlM :: (Monad m, Prim prim) => PrimArray prim -> UnfoldlM m prim+toElementsUnfoldlM ba = UnfoldlM $ \f z -> foldlPrimArrayM' f z ba toByteArray :: PrimArray a -> ByteArray toByteArray (PrimArray unliftedByteArray) =
library/PrimitiveExtras/PrimMultiArray.hs view
@@ -4,12 +4,12 @@ create, replicateM, outerLength,- toAssocsUnfold,- toIndicesUnfold,- toUnfoldAt,- toAssocsUnfoldM,- toIndicesUnfoldM,- toUnfoldAtM,+ toAssocsUnfoldl,+ toIndicesUnfoldl,+ toUnfoldlAt,+ toAssocsUnfoldlM,+ toIndicesUnfoldlM,+ toUnfoldlAtM, cerealGet, cerealGetAsInMemory, cerealPut,@@ -20,8 +20,8 @@ import PrimitiveExtras.Prelude hiding (replicateM, fold) import PrimitiveExtras.Types-import qualified DeferredFolds.Unfold as Unfold-import qualified DeferredFolds.UnfoldM as UnfoldM+import qualified DeferredFolds.Unfoldl as Unfoldl+import qualified DeferredFolds.UnfoldlM as UnfoldlM import qualified PrimitiveExtras.UnliftedArray as UnliftedArray import qualified PrimitiveExtras.PrimArray as PrimArray import qualified PrimitiveExtras.Folds as Folds@@ -64,27 +64,27 @@ outerLength :: PrimMultiArray a -> Int outerLength (PrimMultiArray outerDimension) = sizeofUnliftedArray outerDimension -toAssocsUnfold :: Prim a => PrimMultiArray a -> Unfold (Int, a)-toAssocsUnfold = Unfold.unfoldM . toAssocsUnfoldM+toAssocsUnfoldl :: Prim a => PrimMultiArray a -> Unfoldl (Int, a)+toAssocsUnfoldl = Unfoldl.unfoldlM . toAssocsUnfoldlM -toIndicesUnfold :: PrimMultiArray a -> Unfold Int-toIndicesUnfold (PrimMultiArray ua) = Unfold.intsInRange 0 (pred (sizeofUnliftedArray ua))+toIndicesUnfoldl :: PrimMultiArray a -> Unfoldl Int+toIndicesUnfoldl (PrimMultiArray ua) = Unfoldl.intsInRange 0 (pred (sizeofUnliftedArray ua)) -toUnfoldAt :: Prim prim => PrimMultiArray prim -> Int -> Unfold prim-toUnfoldAt (PrimMultiArray ua) index = UnliftedArray.at ua index empty PrimArray.toElementsUnfold+toUnfoldlAt :: Prim prim => PrimMultiArray prim -> Int -> Unfoldl prim+toUnfoldlAt (PrimMultiArray ua) index = UnliftedArray.at ua index empty PrimArray.toElementsUnfoldl -toAssocsUnfoldM :: (Monad m, Prim a) => PrimMultiArray a -> UnfoldM m (Int, a)-toAssocsUnfoldM pma =+toAssocsUnfoldlM :: (Monad m, Prim a) => PrimMultiArray a -> UnfoldlM m (Int, a)+toAssocsUnfoldlM pma = do- index <- toIndicesUnfoldM pma- element <- toUnfoldAtM pma index+ index <- toIndicesUnfoldlM pma+ element <- toUnfoldlAtM pma index return (index, element) -toIndicesUnfoldM :: Monad m => PrimMultiArray a -> UnfoldM m Int-toIndicesUnfoldM (PrimMultiArray ua) = UnfoldM.intsInRange 0 (pred (sizeofUnliftedArray ua))+toIndicesUnfoldlM :: Monad m => PrimMultiArray a -> UnfoldlM m Int+toIndicesUnfoldlM (PrimMultiArray ua) = UnfoldlM.intsInRange 0 (pred (sizeofUnliftedArray ua)) -toUnfoldAtM :: (Monad m, Prim prim) => PrimMultiArray prim -> Int -> UnfoldM m prim-toUnfoldAtM (PrimMultiArray ua) index = UnliftedArray.at ua index empty PrimArray.toElementsUnfoldM+toUnfoldlAtM :: (Monad m, Prim prim) => PrimMultiArray prim -> Int -> UnfoldlM m prim+toUnfoldlAtM (PrimMultiArray ua) index = UnliftedArray.at ua index empty PrimArray.toElementsUnfoldlM cerealGet :: Prim element => Cereal.Get Int -> Cereal.Get element -> Cereal.Get (PrimMultiArray element) cerealGet int element =
library/PrimitiveExtras/SmallArray.hs view
@@ -129,9 +129,9 @@ else Nothing in iterate 0 -{-# INLINE elementsUnfoldM #-}-elementsUnfoldM :: Monad m => SmallArray e -> UnfoldM m e-elementsUnfoldM array = UnfoldM $ \ step initialState -> let+{-# INLINE elementsUnfoldlM #-}+elementsUnfoldlM :: Monad m => SmallArray e -> UnfoldlM m e+elementsUnfoldlM array = UnfoldlM $ \ step initialState -> let !size = sizeofSmallArray array iterate index !state = if index < size then do@@ -178,4 +178,4 @@ Focus.Remove -> empty toList :: forall a. SmallArray a -> [a]-toList array = PrimitiveExtras.Prelude.toList (elementsUnfoldM array :: UnfoldM Identity a)+toList array = PrimitiveExtras.Prelude.toList (elementsUnfoldlM array :: UnfoldlM Identity a)
library/PrimitiveExtras/SparseSmallArray.hs view
@@ -12,8 +12,8 @@ focusAt, toMaybeList, toIndexedList,- elementsUnfold,- elementsUnfoldM,+ elementsUnfoldl,+ elementsUnfoldlM, elementsListT, onElementAtFocus, null,@@ -36,11 +36,11 @@ instance Foldable SparseSmallArray where {-# INLINE foldr #-}- foldr step state = foldr step state . elementsUnfold+ foldr step state = foldr step state . elementsUnfoldl {-# INLINE foldl' #-}- foldl' step state = foldl' step state . elementsUnfold+ foldl' step state = foldl' step state . elementsUnfoldl {-# INLINE foldMap #-}- foldMap monoid = foldMap monoid . elementsUnfold+ foldMap monoid = foldMap monoid . elementsUnfoldl {-# INLINE empty #-} empty :: SparseSmallArray e@@ -126,13 +126,13 @@ toIndexedList :: SparseSmallArray e -> [(Int, e)] toIndexedList = catMaybes . zipWith (\i -> fmap (i,)) [0..] . toMaybeList -{-# INLINE elementsUnfold #-}-elementsUnfold :: SparseSmallArray e -> Unfold e-elementsUnfold (SparseSmallArray _ array) = Unfold (\ f z -> foldl' f z array)+{-# INLINE elementsUnfoldl #-}+elementsUnfoldl :: SparseSmallArray e -> Unfoldl e+elementsUnfoldl (SparseSmallArray _ array) = Unfoldl (\ f z -> foldl' f z array) -{-# INLINE elementsUnfoldM #-}-elementsUnfoldM :: Monad m => SparseSmallArray a -> UnfoldM m a-elementsUnfoldM (SparseSmallArray _ array) = SmallArray.elementsUnfoldM array+{-# INLINE elementsUnfoldlM #-}+elementsUnfoldlM :: Monad m => SparseSmallArray a -> UnfoldlM m a+elementsUnfoldlM (SparseSmallArray _ array) = SmallArray.elementsUnfoldlM array {-# INLINE elementsListT #-} elementsListT :: SparseSmallArray a -> ListT STM a
primitive-extras.cabal view
@@ -1,5 +1,5 @@ name: primitive-extras-version: 0.6.7+version: 0.7 category: Primitive synopsis: Extras for the "primitive" library homepage: https://github.com/metrix-ai/primitive-extras@@ -37,7 +37,7 @@ base >=4.7 && <5, bytestring >=0.10 && <0.11, cereal >=0.5.5 && <0.6,- deferred-folds >=0.6.5 && <0.7,+ deferred-folds >=0.7 && <0.8, focus >=1 && <1.1, foldl >=1 && <2, list-t >=1.0.1 && <1.1,
test/Main.hs view
@@ -83,7 +83,7 @@ , testTransactionProperty "focusDelete" Gen.focusDeleteTransaction ,- testTransactionProperty "unfold" Gen.unfoldTransaction+ testTransactionProperty "unfoldl" Gen.unfoldlTransaction , testTransactionProperty "lookup" Gen.lookupTransaction ,
test/Main/Gens.hs view
@@ -30,8 +30,8 @@ unsetTransaction :: Gen (Transaction element) unsetTransaction = Transaction.unset <$> index -unfoldTransaction :: (Show element, Eq element) => Gen (Transaction element)-unfoldTransaction = pure Transaction.elementsUnfold+unfoldlTransaction :: (Show element, Eq element) => Gen (Transaction element)+unfoldlTransaction = pure Transaction.elementsUnfoldl transaction :: Gen (Transaction Int) transaction =
test/Main/Transaction.hs view
@@ -5,7 +5,7 @@ import qualified Focus import qualified PrimitiveExtras.SparseSmallArray as SparseSmallArray import qualified Data.Text as Text-import qualified DeferredFolds.Unfold as Unfold+import qualified DeferredFolds.Unfoldl as Unfoldl data Transaction element = forall result. (Show result, Eq result) => Transaction {@@ -70,17 +70,17 @@ applyToSparseSmallArray = fmap (SparseSmallArray.lookup index) get } -elementsUnfold :: (Show element, Eq element) => Transaction element-elementsUnfold =+elementsUnfoldl :: (Show element, Eq element) => Transaction element+elementsUnfoldl = Transaction {- name = "elementsUnfold",+ name = "elementsUnfoldl", applyToMaybeList = do list <- get return $ do- maybeElement <- Unfold.foldable list- element <- Unfold.foldable maybeElement+ maybeElement <- Unfoldl.foldable list+ element <- Unfoldl.foldable maybeElement return element,- applyToSparseSmallArray = fmap SparseSmallArray.elementsUnfold get+ applyToSparseSmallArray = fmap SparseSmallArray.elementsUnfoldl get } focusAt :: (Show element, Eq result, Show result) => Text -> Focus element Identity result -> Int -> Transaction element