-
Notifications
You must be signed in to change notification settings - Fork 60
foldMap, foldMap' for PrimArray #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
ff7f68a
6948536
853b996
af41b39
0bb9dd6
8aaa9d1
96eb0cc
534a20c
6f0c84e
d4eb3d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,10 @@ module Data.Primitive.PrimArray | |
| , foldlPrimArray | ||
| , foldlPrimArray' | ||
| , foldlPrimArrayM' | ||
| , foldrMapPrimArray | ||
| , foldlMapPrimArray | ||
| , foldrMapPrimArray' | ||
| , foldlMapPrimArray' | ||
| -- * Effectful Folding | ||
| , traversePrimArray_ | ||
| , itraversePrimArray_ | ||
|
|
@@ -467,6 +471,32 @@ sizeofPrimArray :: forall a. Prim a => PrimArray a -> Int | |
| {-# INLINE sizeofPrimArray #-} | ||
| sizeofPrimArray (PrimArray arr#) = I# (quotInt# (sizeofByteArray# arr#) (sizeOf# (undefined :: a))) | ||
|
|
||
| -- | Map each element of the primitive array to a monoid, and combine the results. | ||
| -- The combination is right-associated, and the accumulation is lazy. | ||
| foldrMapPrimArray :: forall a m. (Prim a, Monoid m) => (a -> m) -> PrimArray a -> m | ||
|
||
| {-# INLINE foldrMapPrimArray #-} | ||
| foldrMapPrimArray f = foldrPrimArray (\a acc -> f a `mappend` acc) mempty | ||
|
|
||
| -- | Map each element of the primitive array to a monoid, and combine the results. | ||
| -- The combination is left-associated, and the accumulation is lazy. | ||
chessai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| foldlMapPrimArray :: forall a m. (Prim a, Monoid m) => (a -> m) -> PrimArray a -> m | ||
| {-# INLINE foldlMapPrimArray #-} | ||
| foldlMapPrimArray f = foldlPrimArray (\acc a -> acc `mappend` f a) mempty | ||
|
|
||
| -- | Map each element of the primitive array to a monoid, and combine the results. | ||
| -- The combination is right-associated, and the accumulation is strict, though | ||
| -- this function is not necessarily strict in its result. | ||
|
||
| foldrMapPrimArray' :: forall a m. (Prim a, Monoid m) => (a -> m) -> PrimArray a -> m | ||
| {-# INLINE foldrMapPrimArray' #-} | ||
| foldrMapPrimArray' f = foldrPrimArray (\a !acc -> f a `mappend` acc) mempty | ||
|
|
||
| -- | Map each element of the primitive array to a monoid, and combine the results. | ||
| -- The combination is left-associated, and the accumulation is strict, though | ||
| -- this function is not necessarily strict in its result. | ||
| foldlMapPrimArray' :: forall a m. (Prim a, Monoid m) => (a -> m) -> PrimArray a -> m | ||
| {-# INLINE foldlMapPrimArray' #-} | ||
| foldlMapPrimArray' f = foldlPrimArray (\ !acc a -> acc `mappend` f a) mempty | ||
|
|
||
| -- | Lazy right-associated fold over the elements of a 'PrimArray'. | ||
| {-# INLINE foldrPrimArray #-} | ||
| foldrPrimArray :: forall a b. Prim a => (a -> b -> b) -> b -> PrimArray a -> b | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,9 @@ | |
|
|
||
| ## Changes in version 0.6.4.1 | ||
|
|
||
| * Add instances for the following newtypes from `base`: | ||
| * Add `foldMapPrimArray` and `foldMapPrimArray'` | ||
|
||
|
|
||
| * Add `Prim` instances for the following newtypes from `base`: | ||
| `Const`, `Identity`, `Down`, `Dual`, `Sum`, `Product`, | ||
| `First`, `Last`, `Min`, `Max` | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.