mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 11:37:22 +03:00
Rename createLastOf to createOfLast
createLastOf sounds weird. createOfLast sounds more correct. create - Array - Of - Last - N - elements
This commit is contained in:
parent
c3cf4d5b6e
commit
ed72f22af0
@ -98,10 +98,10 @@ o_1_space_elimination :: Int -> [Benchmark]
|
||||
o_1_space_elimination value =
|
||||
[ bgroup "elimination"
|
||||
[ benchPureSink value "length . IsList.toList" (length . GHC.toList)
|
||||
, benchFold "createLastOf.1"
|
||||
(S.fold (IA.createLastOf 1)) (P.sourceUnfoldrM value)
|
||||
, benchFold "createLastOf.10"
|
||||
(S.fold (IA.createLastOf 10)) (P.sourceUnfoldrM value)
|
||||
, benchFold "createOfLast.1"
|
||||
(S.fold (IA.createOfLast 1)) (P.sourceUnfoldrM value)
|
||||
, benchFold "createOfLast.10"
|
||||
(S.fold (IA.createOfLast 10)) (P.sourceUnfoldrM value)
|
||||
#ifdef DEVBUILD
|
||||
{-
|
||||
benchPureSink value "foldable/foldl'" foldableFoldl'
|
||||
@ -116,7 +116,7 @@ o_n_heap_serial value =
|
||||
[ bgroup "elimination"
|
||||
[
|
||||
-- Converting the stream to an array
|
||||
benchFold "createLastOf.Max" (S.fold (IA.createLastOf (value + 1)))
|
||||
benchFold "createOfLast.Max" (S.fold (IA.createOfLast (value + 1)))
|
||||
(P.sourceUnfoldrM value)
|
||||
]
|
||||
]
|
||||
|
@ -77,10 +77,10 @@ o_1_space_generation value =
|
||||
o_1_space_elimination :: Int -> [Benchmark]
|
||||
o_1_space_elimination value =
|
||||
[ bgroup "elimination"
|
||||
[ benchFold "createLastOf.1"
|
||||
(S.fold (IA.createLastOf 1)) (P.sourceUnfoldrM value)
|
||||
, benchFold "createLastOf.10"
|
||||
(S.fold (IA.createLastOf 10)) (P.sourceUnfoldrM value)
|
||||
[ benchFold "createOfLast.1"
|
||||
(S.fold (IA.createOfLast 1)) (P.sourceUnfoldrM value)
|
||||
, benchFold "createOfLast.10"
|
||||
(S.fold (IA.createOfLast 10)) (P.sourceUnfoldrM value)
|
||||
#ifdef DEVBUILD
|
||||
{-
|
||||
benchPureSink value "foldable/foldl'" foldableFoldl'
|
||||
@ -95,7 +95,7 @@ o_n_heap_serial value =
|
||||
[ bgroup "elimination"
|
||||
[
|
||||
-- Converting the stream to an array
|
||||
benchFold "createLastOf.Max" (S.fold (IA.createLastOf (value + 1)))
|
||||
benchFold "createOfLast.Max" (S.fold (IA.createOfLast (value + 1)))
|
||||
(P.sourceUnfoldrM value)
|
||||
]
|
||||
]
|
||||
|
@ -55,7 +55,7 @@ module Streamly.Data.Array
|
||||
-- ** From Stream
|
||||
, createOf
|
||||
, create
|
||||
, createLastOf -- drop old (ring buffer)
|
||||
, createOfLast -- drop old (ring buffer)
|
||||
|
||||
-- ** From List
|
||||
, fromListN
|
||||
|
@ -40,7 +40,7 @@ module Streamly.Data.MutArray
|
||||
, fromList
|
||||
, createOf
|
||||
, create
|
||||
-- createLastOf
|
||||
-- createOfLast
|
||||
|
||||
-- * Pinning & Unpinning
|
||||
, pin
|
||||
|
@ -20,7 +20,7 @@ module Streamly.Internal.Data.Array
|
||||
|
||||
-- * Construction
|
||||
-- Monadic Folds
|
||||
, createLastOf
|
||||
, createOfLast
|
||||
|
||||
-- * Random Access
|
||||
-- , (!!)
|
||||
@ -207,13 +207,13 @@ last = getIndexRev 0
|
||||
|
||||
-- XXX We should generate this from Ring.
|
||||
|
||||
-- | @createLastOf n@ folds a maximum of @n@ elements from the end of the input
|
||||
-- | @createOfLast n@ folds a maximum of @n@ elements from the end of the input
|
||||
-- stream to an 'Array'.
|
||||
--
|
||||
{-# INLINE createLastOf #-}
|
||||
createLastOf ::
|
||||
{-# INLINE createOfLast #-}
|
||||
createOfLast ::
|
||||
(Unbox a, MonadIO m) => Int -> Fold m a (Array a)
|
||||
createLastOf n
|
||||
createOfLast n
|
||||
| n <= 0 = fmap (const mempty) FL.drain
|
||||
| otherwise = unsafeFreeze <$> Fold step initial done done
|
||||
|
||||
@ -236,10 +236,10 @@ createLastOf n
|
||||
| i < n = RB.unsafeFoldRingM
|
||||
| otherwise = RB.unsafeFoldRingFullM
|
||||
|
||||
{-# DEPRECATED writeLastN "Please use createLastOf instead." #-}
|
||||
{-# DEPRECATED writeLastN "Please use createOfLast instead." #-}
|
||||
{-# INLINE writeLastN #-}
|
||||
writeLastN :: (Unbox a, MonadIO m) => Int -> Fold m a (Array a)
|
||||
writeLastN = createLastOf
|
||||
writeLastN = createOfLast
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Random Access
|
||||
|
@ -14,7 +14,7 @@ module Streamly.Internal.Data.Array.Generic
|
||||
, createOf
|
||||
, create
|
||||
, createWith
|
||||
, createLastOf
|
||||
, createOfLast
|
||||
|
||||
, fromStreamN
|
||||
, fromStream
|
||||
@ -267,14 +267,14 @@ getIndex i arr@Array {..} =
|
||||
-- >>> import Data.Function ((&))
|
||||
-- >>> :{
|
||||
-- Stream.fromList [1,2,3,4,5::Int]
|
||||
-- & Stream.scan (Array.createLastOf 2)
|
||||
-- & Stream.scan (Array.createOfLast 2)
|
||||
-- & Stream.fold Fold.toList
|
||||
-- :}
|
||||
-- [fromList [],fromList [1],fromList [1,2],fromList [2,3],fromList [3,4],fromList [4,5]]
|
||||
--
|
||||
{-# INLINE createLastOf #-}
|
||||
createLastOf :: MonadIO m => Int -> Fold m a (Array a)
|
||||
createLastOf n = FL.rmapM f (RB.createOf n)
|
||||
{-# INLINE createOfLast #-}
|
||||
createOfLast :: MonadIO m => Int -> Fold m a (Array a)
|
||||
createOfLast n = FL.rmapM f (RB.createOf n)
|
||||
|
||||
where
|
||||
|
||||
|
@ -152,7 +152,7 @@ advance rb ringHead =
|
||||
moveBy :: Int -> Ring a -> Int -> Int
|
||||
moveBy by rb ringHead = (ringHead + by) `mod1` ringCapacity rb
|
||||
|
||||
-- XXX Move the createLastOf from array module here.
|
||||
-- XXX Move the createOfLast from array module here.
|
||||
--
|
||||
-- | @createOf n@ is a rolling fold that keeps the last n elements of the stream
|
||||
-- in a ring array.
|
||||
|
@ -200,7 +200,7 @@ specialize in the last phase, inlining in the last phase is left to
|
||||
the compiler. `INLINE [0]` may sound the same as `NOINLINE [0]`,
|
||||
however, it behaves differently because we ask the compiler to INLINE
|
||||
it compulsorily and it may not give us the desired results. The
|
||||
Data.Fold.createLastOf benchmark is one such case where `NOINLINE [0]`
|
||||
Data.Fold.createOfLast benchmark is one such case where `NOINLINE [0]`
|
||||
provides much better performance than `INLINE [0]`.
|
||||
|
||||
### NoSpecConstr
|
||||
|
@ -79,13 +79,13 @@ $(mkZippingType "ZipConcurrent" "app" True)
|
||||
|
||||
## Sliding Window
|
||||
|
||||
The `createLastOf` fold can be used to create a stream of sliding windows.
|
||||
The `createOfLast` fold can be used to create a stream of sliding windows.
|
||||
|
||||
```haskell docspec
|
||||
>>> import qualified Streamly.Data.Array as Array
|
||||
>>> :{
|
||||
Stream.fromList [1,2,3,4,5::Int]
|
||||
& Stream.scan (Array.createLastOf 2)
|
||||
& Stream.scan (Array.createOfLast 2)
|
||||
& Stream.fold Fold.toList
|
||||
:}
|
||||
[fromList [],fromList [1],fromList [1,2],fromList [2,3],fromList [3,4],fromList [4,5]]
|
||||
|
@ -67,14 +67,14 @@ testLastN =
|
||||
monadicIO $ do
|
||||
xs <- run
|
||||
$ fmap A.toList
|
||||
$ S.fold (A.createLastOf n)
|
||||
$ S.fold (A.createOfLast n)
|
||||
$ S.fromList list
|
||||
assert (xs == lastN n list)
|
||||
|
||||
testLastN_LN :: Int -> Int -> IO Bool
|
||||
testLastN_LN len n = do
|
||||
let list = [1..len]
|
||||
l1 <- fmap A.toList $ S.fold (A.createLastOf n) $ S.fromList list
|
||||
l1 <- fmap A.toList $ S.fold (A.createOfLast n) $ S.fromList list
|
||||
let l2 = lastN n list
|
||||
return $ l1 == l2
|
||||
|
||||
@ -239,12 +239,12 @@ main =
|
||||
it "middle" (unsafeWriteIndex [1..10] 5 0 `shouldReturn` True)
|
||||
it "last" (unsafeWriteIndex [1..10] 9 0 `shouldReturn` True)
|
||||
describe "Fold" $ do
|
||||
prop "createLastOf : 0 <= n <= len" testLastN
|
||||
describe "createLastOf boundary conditions" $ do
|
||||
it "createLastOf -1" (testLastN_LN 10 (-1) `shouldReturn` True)
|
||||
it "createLastOf 0" (testLastN_LN 10 0 `shouldReturn` True)
|
||||
it "createLastOf length" (testLastN_LN 10 10 `shouldReturn` True)
|
||||
it "createLastOf (length + 1)" (testLastN_LN 10 11 `shouldReturn` True)
|
||||
prop "createOfLast : 0 <= n <= len" testLastN
|
||||
describe "createOfLast boundary conditions" $ do
|
||||
it "createOfLast -1" (testLastN_LN 10 (-1) `shouldReturn` True)
|
||||
it "createOfLast 0" (testLastN_LN 10 0 `shouldReturn` True)
|
||||
it "createOfLast length" (testLastN_LN 10 10 `shouldReturn` True)
|
||||
it "createOfLast (length + 1)" (testLastN_LN 10 11 `shouldReturn` True)
|
||||
describe "Strip" $ do
|
||||
it "strip" (testStrip `shouldReturn` True)
|
||||
it "stripLeft" (testStripLeft `shouldReturn` True)
|
||||
|
Loading…
Reference in New Issue
Block a user