on master help sign in
Move splitOn to lower level MutArray module
471de54Harendra Kumar
core/src/Streamly/Internal/Data/Array.hs+1−1
@@ -46,7 +46,7 @@ module Streamly.Internal.Data.Array
46
46
47 -- * Search
47 -- * Search
48 , binarySearch
48 , binarySearch
49− , findIndicesOf
49+ , findIndicesOf -- see splitOn, rename to indicesOf
50 -- , findIndexOf
50 -- , findIndexOf
51 -- , find
51 -- , find
52
52
core/src/Streamly/Internal/Data/MutArray.hs−16
@@ -11,14 +11,12 @@ module Streamly.Internal.Data.MutArray
11 -- * MutArray.Type module
11 -- * MutArray.Type module
12 module Streamly.Internal.Data.MutArray.Type
12 module Streamly.Internal.Data.MutArray.Type
13 -- * MutArray module
13 -- * MutArray module
14− , splitOn
15 , sliceIndexerFromLen
14 , sliceIndexerFromLen
16 , slicerFromLen
15 , slicerFromLen
17 -- * Unboxed IORef
16 -- * Unboxed IORef
18 , module Streamly.Internal.Data.IORef.Unboxed
17 , module Streamly.Internal.Data.IORef.Unboxed
19
18
20 -- * Deprecated
19 -- * Deprecated
21− , splitOn
22 , genSlicesFromLen
20 , genSlicesFromLen
23 , getSlicesFromLen
21 , getSlicesFromLen
24 )
22 )
@@ -26,29 +24,15 @@ where
26
24
27#include "inline.hs"
25#include "inline.hs"
28
26
29−import Control.Monad.IO.Class (MonadIO(..))
30import Streamly.Internal.Data.Unbox (Unbox)
27import Streamly.Internal.Data.Unbox (Unbox)
31−import Streamly.Internal.Data.Stream (Stream)
32import Streamly.Internal.Data.Unfold.Type (Unfold(..))
28import Streamly.Internal.Data.Unfold.Type (Unfold(..))
33
29
34−import qualified Streamly.Internal.Data.Stream as D
35import qualified Streamly.Internal.Data.Unfold as Unfold
30import qualified Streamly.Internal.Data.Unfold as Unfold
36
31
37import Prelude hiding (foldr, length, read, splitAt)
32import Prelude hiding (foldr, length, read, splitAt)
38import Streamly.Internal.Data.MutArray.Type
33import Streamly.Internal.Data.MutArray.Type
39import Streamly.Internal.Data.IORef.Unboxed
34import Streamly.Internal.Data.IORef.Unboxed
40
35
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−
52-- | Generate a stream of array slice descriptors ((index, len)) of specified
36-- | Generate a stream of array slice descriptors ((index, len)) of specified
53-- length from an array, starting from the supplied array index. The last slice
37-- length from an array, starting from the supplied array index. The last slice
54-- may be shorter than the requested length depending on the array length.
38-- 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
209 , getSlice
209 , getSlice
210 -- , getSlicesFromLenN
210 -- , getSlicesFromLenN
211 , splitAt -- XXX should be able to express using getSlice
211 , splitAt -- XXX should be able to express using getSlice
212+ , splitOn
212 , breakOn
213 , breakOn
213
214
214 -- ** Cloning arrays
215 -- ** Cloning arrays
@@ -2384,6 +2385,17 @@ spliceExp = spliceWith (\l1 l2 -> max (l1 * 2) (l1 + l2))
2384-- Splitting
2385-- Splitting
2385-------------------------------------------------------------------------------
2386-------------------------------------------------------------------------------
2386
2387
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+
2387-- | Drops the separator byte
2399-- | Drops the separator byte
2388{-# INLINE breakOn #-}
2400{-# INLINE breakOn #-}
2389breakOn :: MonadIO m
2401breakOn :: MonadIO m