From 14c8bf788c8a7f9e4064930dd9cedd826595e636 Mon Sep 17 00:00:00 2001 From: toyboot4e Date: Thu, 5 Jun 2025 22:00:51 +0900 Subject: [PATCH 1/4] Add `iconcatMap`, `concatMapM` and `iconcatMapM` --- vector/src/Data/Vector.hs | 27 +++++++++++++++++-- vector/src/Data/Vector/Generic.hs | 37 +++++++++++++++++++++++++-- vector/src/Data/Vector/Primitive.hs | 27 +++++++++++++++++-- vector/src/Data/Vector/Storable.hs | 27 +++++++++++++++++-- vector/src/Data/Vector/Strict.hs | 27 +++++++++++++++++-- vector/src/Data/Vector/Unboxed.hs | 27 +++++++++++++++++-- vector/tests/Tests/Vector/Property.hs | 20 +++++++++++++-- vector/tests/Utilities.hs | 9 +++++++ 8 files changed, 187 insertions(+), 14 deletions(-) diff --git a/vector/src/Data/Vector.hs b/vector/src/Data/Vector.hs index 991dae5a..e30daaa4 100644 --- a/vector/src/Data/Vector.hs +++ b/vector/src/Data/Vector.hs @@ -94,11 +94,11 @@ module Data.Vector ( indexed, -- ** Mapping - map, imap, concatMap, + map, imap, concatMap, iconcatMap, -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, + iforM, iforM_, concatMapM, iconcatMapM, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -1096,6 +1096,13 @@ concatMap :: (a -> Vector b) -> Vector a -> Vector b {-# INLINE concatMap #-} concatMap = G.concatMap +-- | Map a function to every element of a vector and its index, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMap :: (Int -> a -> Vector b) -> Vector a -> Vector b +{-# INLINE iconcatMap #-} +iconcatMap = G.iconcatMap + -- Monadic mapping -- --------------- @@ -1151,6 +1158,22 @@ iforM_ :: Monad m => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ +-- | Apply the monadic action to all elements of the vector, yielding a vector of results, and +-- concatenate the results. +-- +-- @since 0.13.3.0 +concatMapM :: (Monad m) => (a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE concatMapM #-} +concatMapM = G.concatMapM + +-- | Apply the monadic action to every element of the vector and its index, yielding a vector of +-- results, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMapM :: (Monad m) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE iconcatMapM #-} +iconcatMapM = G.iconcatMapM + -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Generic.hs b/vector/src/Data/Vector/Generic.hs index 35acd0fb..b3cb0af5 100644 --- a/vector/src/Data/Vector/Generic.hs +++ b/vector/src/Data/Vector/Generic.hs @@ -84,11 +84,11 @@ module Data.Vector.Generic ( indexed, -- ** Mapping - map, imap, concatMap, + map, imap, concatMap, iconcatMap, -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, + iforM, iforM_, concatMapM, iconcatMapM, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -1112,6 +1112,16 @@ concatMap f = unstream . Bundle.map f . stream +-- | Apply a function to every element of a vector and its index, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMap :: (Vector v a, Vector v b) => (Int -> a -> v b) -> v a -> v b +{-# INLINE iconcatMap #-} +iconcatMap f = unstream + . Bundle.concatVectors + . Bundle.inplace (S.map (uncurry f) . S.indexed) id + . stream + -- Monadic mapping -- --------------- @@ -1167,6 +1177,29 @@ iforM_ :: (Monad m, Vector v a) => v a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ as f = imapM_ f as +-- | Apply the monadic action to all elements of the vector, yielding a vector of results, and +-- concatenate the results. +-- +-- @since 0.13.3.0 +concatMapM :: (Monad m, Vector v a, Vector v b) => (a -> m (v b)) -> v a -> m (v b) +{-# INLINE concatMapM #-} +concatMapM f = unstreamM + . MBundle.concatVectors + . MBundle.mapM f + . MBundle.fromVector + +-- | Apply the monadic action to every element of the vector and its index, yielding a vector of +-- results, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMapM :: (Monad m, Vector v a, Vector v b) => (Int -> a -> m (v b)) -> v a -> m (v b) +{-# INLINE iconcatMapM #-} +iconcatMapM f = unstreamM + . MBundle.concatVectors + . MBundle.mapM (uncurry f) + . MBundle.indexed + . MBundle.fromVector + -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Primitive.hs b/vector/src/Data/Vector/Primitive.hs index 2d67fba7..5954579a 100644 --- a/vector/src/Data/Vector/Primitive.hs +++ b/vector/src/Data/Vector/Primitive.hs @@ -84,11 +84,11 @@ module Data.Vector.Primitive ( -- * Elementwise operations -- ** Mapping - map, imap, concatMap, + map, imap, concatMap, iconcatMap, -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, + iforM, iforM_, concatMapM, iconcatMapM, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -882,6 +882,13 @@ concatMap :: (Prim a, Prim b) => (a -> Vector b) -> Vector a -> Vector b {-# INLINE concatMap #-} concatMap = G.concatMap +-- | Apply a function to every element of a vector and its index, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMap :: (Prim a, Prim b) => (Int -> a -> Vector b) -> Vector a -> Vector b +{-# INLINE iconcatMap #-} +iconcatMap = G.iconcatMap + -- Monadic mapping -- --------------- @@ -942,6 +949,22 @@ iforM_ :: (Monad m, Prim a) => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ +-- | Apply the monadic action to all elements of the vector, yielding a vector of results, and +-- concatenate the results. +-- +-- @since 0.13.3.0 +concatMapM :: (Monad m, Prim a, Prim b) => (a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE concatMapM #-} +concatMapM = G.concatMapM + +-- | Apply the monadic action to every element of the vector and its index, yielding a vector of +-- results, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMapM :: (Monad m, Prim a, Prim b) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE iconcatMapM #-} +iconcatMapM = G.iconcatMapM + -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Storable.hs b/vector/src/Data/Vector/Storable.hs index 88f2332c..f2bfa423 100644 --- a/vector/src/Data/Vector/Storable.hs +++ b/vector/src/Data/Vector/Storable.hs @@ -81,11 +81,11 @@ module Data.Vector.Storable ( -- * Elementwise operations -- ** Mapping - map, imap, concatMap, + map, imap, concatMap, iconcatMap, -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, + iforM, iforM_, concatMapM, iconcatMapM, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -893,6 +893,13 @@ concatMap :: (Storable a, Storable b) => (a -> Vector b) -> Vector a -> Vector b {-# INLINE concatMap #-} concatMap = G.concatMap +-- | Apply a function to every element of a vector and its index, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMap :: (Storable a, Storable b) => (Int -> a -> Vector b) -> Vector a -> Vector b +{-# INLINE iconcatMap #-} +iconcatMap = G.iconcatMap + -- Monadic mapping -- --------------- @@ -953,6 +960,22 @@ iforM_ :: (Monad m, Storable a) => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ +-- | Apply the monadic action to all elements of the vector, yielding a vector of results, and +-- concatenate the results. +-- +-- @since 0.13.3.0 +concatMapM :: (Monad m, Storable a, Storable b) => (a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE concatMapM #-} +concatMapM = G.concatMapM + +-- | Apply the monadic action to every element of the vector and its index, yielding a vector of +-- results, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMapM :: (Monad m, Storable a, Storable b) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE iconcatMapM #-} +iconcatMapM = G.iconcatMapM + -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Strict.hs b/vector/src/Data/Vector/Strict.hs index faedc2e5..fd6a66db 100644 --- a/vector/src/Data/Vector/Strict.hs +++ b/vector/src/Data/Vector/Strict.hs @@ -92,11 +92,11 @@ module Data.Vector.Strict ( indexed, -- ** Mapping - map, imap, concatMap, + map, imap, concatMap, iconcatMap, -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, + iforM, iforM_, concatMapM, iconcatMapM, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -1175,6 +1175,13 @@ concatMap :: (a -> Vector b) -> Vector a -> Vector b {-# INLINE concatMap #-} concatMap = G.concatMap +-- | Apply a function to every element of a vector and its index, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMap :: (Int -> a -> Vector b) -> Vector a -> Vector b +{-# INLINE iconcatMap #-} +iconcatMap = G.iconcatMap + -- Monadic mapping -- --------------- @@ -1242,6 +1249,22 @@ iforM_ :: Monad m => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ +-- | Apply the monadic action to all elements of the vector, yielding a vector of results, and +-- concatenate the results. +-- +-- @since 0.13.3.0 +concatMapM :: (Monad m) => (a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE concatMapM #-} +concatMapM = G.concatMapM + +-- | Apply the monadic action to every element of the vector and its index, yielding a vector of +-- results, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMapM :: (Monad m) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE iconcatMapM #-} +iconcatMapM = G.iconcatMapM + -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Unboxed.hs b/vector/src/Data/Vector/Unboxed.hs index 673e4946..3a1ba7fa 100644 --- a/vector/src/Data/Vector/Unboxed.hs +++ b/vector/src/Data/Vector/Unboxed.hs @@ -132,11 +132,11 @@ module Data.Vector.Unboxed ( indexed, -- ** Mapping - map, imap, concatMap, + map, imap, concatMap, iconcatMap, -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, + iforM, iforM_, concatMapM, iconcatMapM, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -931,6 +931,13 @@ concatMap :: (Unbox a, Unbox b) => (a -> Vector b) -> Vector a -> Vector b {-# INLINE concatMap #-} concatMap = G.concatMap +-- | Apply a function to every element of a vector and its index, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMap :: (Unbox a, Unbox b) => (Int -> a -> Vector b) -> Vector a -> Vector b +{-# INLINE iconcatMap #-} +iconcatMap = G.iconcatMap + -- Monadic mapping -- --------------- @@ -987,6 +994,22 @@ iforM_ :: (Monad m, Unbox a) => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ +-- | Apply the monadic action to all elements of the vector, yielding a vector of results, and +-- concatenate the results. +-- +-- @since 0.13.3.0 +concatMapM :: (Monad m, Unbox a, Unbox b) => (a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE concatMapM #-} +concatMapM = G.concatMapM + +-- | Apply the monadic action to every element of the vector and its index, yielding a vector of +-- results, and concatenate the results. +-- +-- @since 0.13.3.0 +iconcatMapM :: (Monad m, Unbox a, Unbox b) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) +{-# INLINE iconcatMapM #-} +iconcatMapM = G.iconcatMapM + -- Zipping -- ------- diff --git a/vector/tests/Tests/Vector/Property.hs b/vector/tests/Tests/Vector/Property.hs index dc8f0b63..0f87129e 100644 --- a/vector/tests/Tests/Vector/Property.hs +++ b/vector/tests/Tests/Vector/Property.hs @@ -147,11 +147,11 @@ testPolymorphicFunctions _ = $(testProperties [ {- 'prop_unsafeBackpermute, -} -- Mapping - 'prop_map, 'prop_imap, 'prop_concatMap, + 'prop_map, 'prop_imap, 'prop_concatMap, 'prop_iconcatMap, -- Monadic mapping 'prop_mapM, 'prop_mapM_, 'prop_forM, 'prop_forM_, - 'prop_imapM, 'prop_imapM_, + 'prop_imapM, 'prop_imapM_, 'prop_concatMapM, 'prop_iconcatMapM, -- Zipping 'prop_zipWith, 'prop_zipWith3, @@ -313,6 +313,17 @@ testPolymorphicFunctions _ = $(testProperties [ = V.imapM `eq` imapM prop_imapM_ :: P ((Int -> a -> Writer [a] ()) -> v a -> Writer [a] ()) = V.imapM_ `eq` imapM_ + + prop_concatMapM = forAll arbitrary $ \xs -> + forAll (sized (\n -> resize (n `div` V.length xs) arbitrary)) $ \f -> unP prop f xs + where + prop :: P ((a -> Identity (v a)) -> v a -> Identity (v a)) = V.concatMapM `eq` concatMapM + + prop_iconcatMapM = forAll arbitrary $ \xs -> + forAll (sized (\n -> resize (n `div` V.length xs) arbitrary)) $ \f -> unP prop f xs + where + prop :: P ((Int -> a -> Identity (v a)) -> v a -> Identity (v a)) = V.iconcatMapM `eq` iconcatMapM + prop_izipWith :: P ((Int -> a -> a -> a) -> v a -> v a -> v a) = V.izipWith `eq` izipWith prop_zipWithM :: P ((a -> a -> Identity a) -> v a -> v a -> Identity (v a)) = V.zipWithM `eq` zipWithM @@ -435,6 +446,11 @@ testPolymorphicFunctions _ = $(testProperties [ where prop :: P ((a -> v a) -> v a -> v a) = V.concatMap `eq` concatMap + prop_iconcatMap = forAll arbitrary $ \xs -> + forAll (sized (\n -> resize (n `div` V.length xs) arbitrary)) $ \f -> unP prop f xs + where + prop :: P ((Int -> a -> v a) -> v a -> v a) = V.iconcatMap `eq` iconcatMap + prop_uniq :: P (v a -> v a) = V.uniq `eq` (map head . group) diff --git a/vector/tests/Utilities.hs b/vector/tests/Utilities.hs index 5aa9e8b0..ae1d1746 100644 --- a/vector/tests/Utilities.hs +++ b/vector/tests/Utilities.hs @@ -286,6 +286,15 @@ imapM = withIndexFirst mapM imapM_ :: Monad m => (Int -> a -> m b) -> [a] -> m () imapM_ = withIndexFirst mapM_ +iconcatMap :: (Int -> a -> [a]) -> [a] -> [a] +iconcatMap f = concat . withIndexFirst map f + +concatMapM :: Monad m => (a -> m [a]) -> [a] -> m [a] +concatMapM f = fmap concat . mapM f + +iconcatMapM :: Monad m => (Int -> a -> m [a]) -> [a] -> m [a] +iconcatMapM f = fmap concat . withIndexFirst mapM f + izipWith :: (Int -> a -> a -> a) -> [a] -> [a] -> [a] izipWith = withIndexFirst zipWith From d055d3a0ab2a970d984edd2d6d29d5f15d49f213 Mon Sep 17 00:00:00 2001 From: toyboot4e Date: Sat, 14 Jun 2025 11:51:26 +0900 Subject: [PATCH 2/4] Remove redundant parentheses --- vector/src/Data/Vector.hs | 4 ++-- vector/src/Data/Vector/Strict.hs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vector/src/Data/Vector.hs b/vector/src/Data/Vector.hs index e30daaa4..83747d8a 100644 --- a/vector/src/Data/Vector.hs +++ b/vector/src/Data/Vector.hs @@ -1162,7 +1162,7 @@ iforM_ = G.iforM_ -- concatenate the results. -- -- @since 0.13.3.0 -concatMapM :: (Monad m) => (a -> m (Vector b)) -> Vector a -> m (Vector b) +concatMapM :: Monad m => (a -> m (Vector b)) -> Vector a -> m (Vector b) {-# INLINE concatMapM #-} concatMapM = G.concatMapM @@ -1170,7 +1170,7 @@ concatMapM = G.concatMapM -- results, and concatenate the results. -- -- @since 0.13.3.0 -iconcatMapM :: (Monad m) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) +iconcatMapM :: Monad m => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) {-# INLINE iconcatMapM #-} iconcatMapM = G.iconcatMapM diff --git a/vector/src/Data/Vector/Strict.hs b/vector/src/Data/Vector/Strict.hs index fd6a66db..7d494954 100644 --- a/vector/src/Data/Vector/Strict.hs +++ b/vector/src/Data/Vector/Strict.hs @@ -1253,7 +1253,7 @@ iforM_ = G.iforM_ -- concatenate the results. -- -- @since 0.13.3.0 -concatMapM :: (Monad m) => (a -> m (Vector b)) -> Vector a -> m (Vector b) +concatMapM :: Monad m => (a -> m (Vector b)) -> Vector a -> m (Vector b) {-# INLINE concatMapM #-} concatMapM = G.concatMapM @@ -1261,7 +1261,7 @@ concatMapM = G.concatMapM -- results, and concatenate the results. -- -- @since 0.13.3.0 -iconcatMapM :: (Monad m) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) +iconcatMapM :: Monad m => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) {-# INLINE iconcatMapM #-} iconcatMapM = G.iconcatMapM From 6bee2b32d48c0488f9c04fa5d6687231550bc17e Mon Sep 17 00:00:00 2001 From: toyboot4e Date: Sat, 14 Jun 2025 12:33:28 +0900 Subject: [PATCH 3/4] Remove monadic `concatMap` variants from PR --- vector/src/Data/Vector.hs | 18 +----------------- vector/src/Data/Vector/Generic.hs | 25 +------------------------ vector/src/Data/Vector/Primitive.hs | 18 +----------------- vector/src/Data/Vector/Storable.hs | 18 +----------------- vector/src/Data/Vector/Strict.hs | 18 +----------------- vector/src/Data/Vector/Unboxed.hs | 18 +----------------- vector/tests/Tests/Vector/Property.hs | 12 +----------- vector/tests/Utilities.hs | 6 ------ 8 files changed, 7 insertions(+), 126 deletions(-) diff --git a/vector/src/Data/Vector.hs b/vector/src/Data/Vector.hs index 83747d8a..9517d4fc 100644 --- a/vector/src/Data/Vector.hs +++ b/vector/src/Data/Vector.hs @@ -98,7 +98,7 @@ module Data.Vector ( -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, concatMapM, iconcatMapM, + iforM, iforM_, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -1158,22 +1158,6 @@ iforM_ :: Monad m => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ --- | Apply the monadic action to all elements of the vector, yielding a vector of results, and --- concatenate the results. --- --- @since 0.13.3.0 -concatMapM :: Monad m => (a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE concatMapM #-} -concatMapM = G.concatMapM - --- | Apply the monadic action to every element of the vector and its index, yielding a vector of --- results, and concatenate the results. --- --- @since 0.13.3.0 -iconcatMapM :: Monad m => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE iconcatMapM #-} -iconcatMapM = G.iconcatMapM - -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Generic.hs b/vector/src/Data/Vector/Generic.hs index b3cb0af5..c2114f7a 100644 --- a/vector/src/Data/Vector/Generic.hs +++ b/vector/src/Data/Vector/Generic.hs @@ -88,7 +88,7 @@ module Data.Vector.Generic ( -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, concatMapM, iconcatMapM, + iforM, iforM_, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -1177,29 +1177,6 @@ iforM_ :: (Monad m, Vector v a) => v a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ as f = imapM_ f as --- | Apply the monadic action to all elements of the vector, yielding a vector of results, and --- concatenate the results. --- --- @since 0.13.3.0 -concatMapM :: (Monad m, Vector v a, Vector v b) => (a -> m (v b)) -> v a -> m (v b) -{-# INLINE concatMapM #-} -concatMapM f = unstreamM - . MBundle.concatVectors - . MBundle.mapM f - . MBundle.fromVector - --- | Apply the monadic action to every element of the vector and its index, yielding a vector of --- results, and concatenate the results. --- --- @since 0.13.3.0 -iconcatMapM :: (Monad m, Vector v a, Vector v b) => (Int -> a -> m (v b)) -> v a -> m (v b) -{-# INLINE iconcatMapM #-} -iconcatMapM f = unstreamM - . MBundle.concatVectors - . MBundle.mapM (uncurry f) - . MBundle.indexed - . MBundle.fromVector - -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Primitive.hs b/vector/src/Data/Vector/Primitive.hs index 5954579a..95d0d790 100644 --- a/vector/src/Data/Vector/Primitive.hs +++ b/vector/src/Data/Vector/Primitive.hs @@ -88,7 +88,7 @@ module Data.Vector.Primitive ( -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, concatMapM, iconcatMapM, + iforM, iforM_, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -949,22 +949,6 @@ iforM_ :: (Monad m, Prim a) => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ --- | Apply the monadic action to all elements of the vector, yielding a vector of results, and --- concatenate the results. --- --- @since 0.13.3.0 -concatMapM :: (Monad m, Prim a, Prim b) => (a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE concatMapM #-} -concatMapM = G.concatMapM - --- | Apply the monadic action to every element of the vector and its index, yielding a vector of --- results, and concatenate the results. --- --- @since 0.13.3.0 -iconcatMapM :: (Monad m, Prim a, Prim b) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE iconcatMapM #-} -iconcatMapM = G.iconcatMapM - -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Storable.hs b/vector/src/Data/Vector/Storable.hs index f2bfa423..65565b05 100644 --- a/vector/src/Data/Vector/Storable.hs +++ b/vector/src/Data/Vector/Storable.hs @@ -85,7 +85,7 @@ module Data.Vector.Storable ( -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, concatMapM, iconcatMapM, + iforM, iforM_, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -960,22 +960,6 @@ iforM_ :: (Monad m, Storable a) => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ --- | Apply the monadic action to all elements of the vector, yielding a vector of results, and --- concatenate the results. --- --- @since 0.13.3.0 -concatMapM :: (Monad m, Storable a, Storable b) => (a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE concatMapM #-} -concatMapM = G.concatMapM - --- | Apply the monadic action to every element of the vector and its index, yielding a vector of --- results, and concatenate the results. --- --- @since 0.13.3.0 -iconcatMapM :: (Monad m, Storable a, Storable b) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE iconcatMapM #-} -iconcatMapM = G.iconcatMapM - -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Strict.hs b/vector/src/Data/Vector/Strict.hs index 7d494954..01143b4b 100644 --- a/vector/src/Data/Vector/Strict.hs +++ b/vector/src/Data/Vector/Strict.hs @@ -96,7 +96,7 @@ module Data.Vector.Strict ( -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, concatMapM, iconcatMapM, + iforM, iforM_, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -1249,22 +1249,6 @@ iforM_ :: Monad m => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ --- | Apply the monadic action to all elements of the vector, yielding a vector of results, and --- concatenate the results. --- --- @since 0.13.3.0 -concatMapM :: Monad m => (a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE concatMapM #-} -concatMapM = G.concatMapM - --- | Apply the monadic action to every element of the vector and its index, yielding a vector of --- results, and concatenate the results. --- --- @since 0.13.3.0 -iconcatMapM :: Monad m => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE iconcatMapM #-} -iconcatMapM = G.iconcatMapM - -- Zipping -- ------- diff --git a/vector/src/Data/Vector/Unboxed.hs b/vector/src/Data/Vector/Unboxed.hs index 3a1ba7fa..f84b38f2 100644 --- a/vector/src/Data/Vector/Unboxed.hs +++ b/vector/src/Data/Vector/Unboxed.hs @@ -136,7 +136,7 @@ module Data.Vector.Unboxed ( -- ** Monadic mapping mapM, imapM, mapM_, imapM_, forM, forM_, - iforM, iforM_, concatMapM, iconcatMapM, + iforM, iforM_, -- ** Zipping zipWith, zipWith3, zipWith4, zipWith5, zipWith6, @@ -994,22 +994,6 @@ iforM_ :: (Monad m, Unbox a) => Vector a -> (Int -> a -> m b) -> m () {-# INLINE iforM_ #-} iforM_ = G.iforM_ --- | Apply the monadic action to all elements of the vector, yielding a vector of results, and --- concatenate the results. --- --- @since 0.13.3.0 -concatMapM :: (Monad m, Unbox a, Unbox b) => (a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE concatMapM #-} -concatMapM = G.concatMapM - --- | Apply the monadic action to every element of the vector and its index, yielding a vector of --- results, and concatenate the results. --- --- @since 0.13.3.0 -iconcatMapM :: (Monad m, Unbox a, Unbox b) => (Int -> a -> m (Vector b)) -> Vector a -> m (Vector b) -{-# INLINE iconcatMapM #-} -iconcatMapM = G.iconcatMapM - -- Zipping -- ------- diff --git a/vector/tests/Tests/Vector/Property.hs b/vector/tests/Tests/Vector/Property.hs index 0f87129e..36301536 100644 --- a/vector/tests/Tests/Vector/Property.hs +++ b/vector/tests/Tests/Vector/Property.hs @@ -151,7 +151,7 @@ testPolymorphicFunctions _ = $(testProperties [ -- Monadic mapping 'prop_mapM, 'prop_mapM_, 'prop_forM, 'prop_forM_, - 'prop_imapM, 'prop_imapM_, 'prop_concatMapM, 'prop_iconcatMapM, + 'prop_imapM, 'prop_imapM_, -- Zipping 'prop_zipWith, 'prop_zipWith3, @@ -314,16 +314,6 @@ testPolymorphicFunctions _ = $(testProperties [ prop_imapM_ :: P ((Int -> a -> Writer [a] ()) -> v a -> Writer [a] ()) = V.imapM_ `eq` imapM_ - prop_concatMapM = forAll arbitrary $ \xs -> - forAll (sized (\n -> resize (n `div` V.length xs) arbitrary)) $ \f -> unP prop f xs - where - prop :: P ((a -> Identity (v a)) -> v a -> Identity (v a)) = V.concatMapM `eq` concatMapM - - prop_iconcatMapM = forAll arbitrary $ \xs -> - forAll (sized (\n -> resize (n `div` V.length xs) arbitrary)) $ \f -> unP prop f xs - where - prop :: P ((Int -> a -> Identity (v a)) -> v a -> Identity (v a)) = V.iconcatMapM `eq` iconcatMapM - prop_izipWith :: P ((Int -> a -> a -> a) -> v a -> v a -> v a) = V.izipWith `eq` izipWith prop_zipWithM :: P ((a -> a -> Identity a) -> v a -> v a -> Identity (v a)) = V.zipWithM `eq` zipWithM diff --git a/vector/tests/Utilities.hs b/vector/tests/Utilities.hs index ae1d1746..77e2be86 100644 --- a/vector/tests/Utilities.hs +++ b/vector/tests/Utilities.hs @@ -289,12 +289,6 @@ imapM_ = withIndexFirst mapM_ iconcatMap :: (Int -> a -> [a]) -> [a] -> [a] iconcatMap f = concat . withIndexFirst map f -concatMapM :: Monad m => (a -> m [a]) -> [a] -> m [a] -concatMapM f = fmap concat . mapM f - -iconcatMapM :: Monad m => (Int -> a -> m [a]) -> [a] -> m [a] -iconcatMapM f = fmap concat . withIndexFirst mapM f - izipWith :: (Int -> a -> a -> a) -> [a] -> [a] -> [a] izipWith = withIndexFirst zipWith From 94344c448993a7e741e574b51f727e893d72abf1 Mon Sep 17 00:00:00 2001 From: toyboot4e Date: Sat, 14 Jun 2025 12:34:26 +0900 Subject: [PATCH 4/4] Clean --- vector/tests/Tests/Vector/Property.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/vector/tests/Tests/Vector/Property.hs b/vector/tests/Tests/Vector/Property.hs index 36301536..135818d7 100644 --- a/vector/tests/Tests/Vector/Property.hs +++ b/vector/tests/Tests/Vector/Property.hs @@ -313,7 +313,6 @@ testPolymorphicFunctions _ = $(testProperties [ = V.imapM `eq` imapM prop_imapM_ :: P ((Int -> a -> Writer [a] ()) -> v a -> Writer [a] ()) = V.imapM_ `eq` imapM_ - prop_izipWith :: P ((Int -> a -> a -> a) -> v a -> v a -> v a) = V.izipWith `eq` izipWith prop_zipWithM :: P ((a -> a -> Identity a) -> v a -> v a -> Identity (v a)) = V.zipWithM `eq` zipWithM