on master help sign in
Move splitOn to lower level MutArray module
commit471de5402d7ebbb74cff6adc18e57c07ca69021b authorHarendra Kumar <harendra@composewell.com> dateSat 30 Dec 2023, 08:20 (3 years ago) parent89a019d
3 files changed+13−17
core/src/Streamly/Internal/Data/Array.hs+1−1 core/src/Streamly/Internal/Data/MutArray.hs−16 core/src/Streamly/Internal/Data/MutArray/Type.hs+12
core/src/Streamly/Internal/Data/Array.hs+1−1
@@ -46,7 +46,7 @@ module Streamly.Internal.Data.Array
4646
4747 -- * Search
4848 , binarySearch
49− , findIndicesOf
49+ , findIndicesOf -- see splitOn, rename to indicesOf
5050 -- , findIndexOf
5151 -- , find
5252
core/src/Streamly/Internal/Data/MutArray.hs−16
@@ -11,14 +11,12 @@ module Streamly.Internal.Data.MutArray
1111 -- * MutArray.Type module
1212 module Streamly.Internal.Data.MutArray.Type
1313 -- * MutArray module
14− , splitOn
1514 , sliceIndexerFromLen
1615 , slicerFromLen
1716 -- * Unboxed IORef
1817 , module Streamly.Internal.Data.IORef.Unboxed
1918
2019 -- * Deprecated
21− , splitOn
2220 , genSlicesFromLen
2321 , getSlicesFromLen
2422 )
@@ -26,29 +24,15 @@ where
2624
2725#include "inline.hs"
2826
29−import Control.Monad.IO.Class (MonadIO(..))
3027import Streamly.Internal.Data.Unbox (Unbox)
31−import Streamly.Internal.Data.Stream (Stream)
3228import Streamly.Internal.Data.Unfold.Type (Unfold(..))
3329
34−import qualified Streamly.Internal.Data.Stream as D
3530import qualified Streamly.Internal.Data.Unfold as Unfold
3631
3732import Prelude hiding (foldr, length, read, splitAt)
3833import Streamly.Internal.Data.MutArray.Type
3934import Streamly.Internal.Data.IORef.Unboxed
4035
41−-- | Split the array into a stream of slices using a predicate. The element
42−-- matching the predicate is dropped.
43−--
44−-- /Pre-release/
45−{-# INLINE splitOn #-}
46−splitOn :: (MonadIO m, Unbox a) =>
47− (a -> Bool) -> MutArray a -> Stream m (MutArray a)
48−splitOn predicate arr =
49− fmap (\(i, len) -> getSliceUnsafe i len arr)
50− $ D.sliceOnSuffix predicate (read arr)
51−
5236-- | Generate a stream of array slice descriptors ((index, len)) of specified
5337-- length from an array, starting from the supplied array index. The last slice
5438-- may be shorter than the requested length depending on the array length.
core/src/Streamly/Internal/Data/MutArray/Type.hs+12
@@ -209,6 +209,7 @@ module Streamly.Internal.Data.MutArray.Type
209209 , getSlice
210210 -- , getSlicesFromLenN
211211 , splitAt -- XXX should be able to express using getSlice
212+ , splitOn
212213 , breakOn
213214
214215 -- ** Cloning arrays
@@ -2384,6 +2385,17 @@ spliceExp = spliceWith (\l1 l2 -> max (l1 * 2) (l1 + l2))
23842385-- Splitting
23852386-------------------------------------------------------------------------------
23862387
2388+-- | Generate a stream of array slices using a predicate. The array element
2389+-- matching the predicate is dropped.
2390+--
2391+-- /Pre-release/
2392+{-# INLINE splitOn #-}
2393+splitOn :: (MonadIO m, Unbox a) =>
2394+ (a -> Bool) -> MutArray a -> Stream m (MutArray a)
2395+splitOn predicate arr =
2396+ fmap (\(i, len) -> getSliceUnsafe i len arr)
2397+ $ D.rangesOnSuffix predicate (read arr)
2398+
23872399-- | Drops the separator byte
23882400{-# INLINE breakOn #-}
23892401breakOn :: MonadIO m