konsumlamm · GitHub

@Shimuuar

konsumlamm

-- Folds
-- -----

forI_ :: (Monad m, MVector v a) => v (PrimState m) a -> (Int -> m b) -> m ()

konsumlamm

@Shimuuar

 - mapM_, imapM_
 - foldl', fold and strict & indexed variants
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

@Shimuuar

@Shimuuar

Shimuuar marked this pull request as ready for review

March 12, 2021 16:47

konsumlamm

And fix API discrepancies for left folds
Note test suite crashes for me at this commit
And fix segfault
Also fix case for negative vector size

@Shimuuar

-- and fill it with the results of applying the function to each index.
generate :: (PrimMonad m, MVector v a) => Int -> (Int -> a) -> m (v (PrimState m) a)
{-# INLINE generate #-}
generate n f = stToPrim $ generateM n (return . f)
-- | /O(n)/ Pure left fold (function applied to each element and its index).
ifoldl :: (PrimMonad m, MVector v a) => (b -> Int -> a -> b) -> b -> v (PrimState m) a -> m b
{-# INLINE ifoldl #-}
ifoldl f b0 v = stToPrim $ loop 0 b0
prop_mut_foldrM' :: P ((a -> a -> Identity a) -> a -> v a -> Identity a)
= (\f z v -> Identity $ runST $ MV.foldrM' (\a b -> pure $ runIdentity $ f a b) z =<< V.thaw v)
`eq`
foldrM
Co-authored-by: Alexey Kuleshevich <lehins@yandex.ru>

konsumlamm

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Bodigrim

@lehins

lehins pushed a commit that referenced this pull request

Apr 1, 2021
Add generate, modifyM & folds for mutable vectors:
* Added `generate`, `generateM` for mutable vectors
* Added `modifyM` and `unsafeModifyM` for mutable vectors
* Add all variants of folds for mutable vectors:
 *  `mapM_`, `imapM_`, `forM_`, `iforM_`
 * `foldl`, `foldl'`, `foldM`, `foldM'`,
 * `foldr, `foldr'`, `foldrM`, `foldrM'`,
 * `ifoldl`, `ifoldl'`, `ifoldM`, `ifoldM'`,
 * `ifoldr`, `ifoldr'`, `ifoldrM, `ifoldrM'`
* Add tests for all new functions
* Update changelog

@Shimuuar

Closed

17 tasks

Read the original on github.com ↗