Skip to content

Commit 7d2863b

Browse files
committed
Rename createLastOf to createOfLast
createLastOf sounds weird. createOfLast sounds more correct. create - Array - Of - Last - N - elements
1 parent ae74466 commit 7d2863b

File tree

10 files changed

+36
-36
lines changed

10 files changed

+36
-36
lines changed

benchmark/Streamly/Benchmark/Data/Array.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ o_1_space_elimination :: Int -> [Benchmark]
9898
o_1_space_elimination value =
9999
[ bgroup "elimination"
100100
[ benchPureSink value "length . IsList.toList" (length . GHC.toList)
101-
, benchFold "createLastOf.1"
102-
(S.fold (IA.createLastOf 1)) (P.sourceUnfoldrM value)
103-
, benchFold "createLastOf.10"
104-
(S.fold (IA.createLastOf 10)) (P.sourceUnfoldrM value)
101+
, benchFold "createOfLast.1"
102+
(S.fold (IA.createOfLast 1)) (P.sourceUnfoldrM value)
103+
, benchFold "createOfLast.10"
104+
(S.fold (IA.createOfLast 10)) (P.sourceUnfoldrM value)
105105
#ifdef DEVBUILD
106106
{-
107107
benchPureSink value "foldable/foldl'" foldableFoldl'
@@ -116,7 +116,7 @@ o_n_heap_serial value =
116116
[ bgroup "elimination"
117117
[
118118
-- Converting the stream to an array
119-
benchFold "createLastOf.Max" (S.fold (IA.createLastOf (value + 1)))
119+
benchFold "createOfLast.Max" (S.fold (IA.createOfLast (value + 1)))
120120
(P.sourceUnfoldrM value)
121121
]
122122
]

benchmark/Streamly/Benchmark/Data/Array/Generic.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ o_1_space_generation value =
7777
o_1_space_elimination :: Int -> [Benchmark]
7878
o_1_space_elimination value =
7979
[ bgroup "elimination"
80-
[ benchFold "createLastOf.1"
81-
(S.fold (IA.createLastOf 1)) (P.sourceUnfoldrM value)
82-
, benchFold "createLastOf.10"
83-
(S.fold (IA.createLastOf 10)) (P.sourceUnfoldrM value)
80+
[ benchFold "createOfLast.1"
81+
(S.fold (IA.createOfLast 1)) (P.sourceUnfoldrM value)
82+
, benchFold "createOfLast.10"
83+
(S.fold (IA.createOfLast 10)) (P.sourceUnfoldrM value)
8484
#ifdef DEVBUILD
8585
{-
8686
benchPureSink value "foldable/foldl'" foldableFoldl'
@@ -95,7 +95,7 @@ o_n_heap_serial value =
9595
[ bgroup "elimination"
9696
[
9797
-- Converting the stream to an array
98-
benchFold "createLastOf.Max" (S.fold (IA.createLastOf (value + 1)))
98+
benchFold "createOfLast.Max" (S.fold (IA.createOfLast (value + 1)))
9999
(P.sourceUnfoldrM value)
100100
]
101101
]

core/src/Streamly/Data/Array.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module Streamly.Data.Array
5555
-- ** From Stream
5656
, createOf
5757
, create
58-
, createLastOf -- drop old (ring buffer)
58+
, createOfLast -- drop old (ring buffer)
5959

6060
-- ** From List
6161
, fromListN

core/src/Streamly/Data/MutArray.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module Streamly.Data.MutArray
4040
, fromList
4141
, createOf
4242
, create
43-
-- createLastOf
43+
-- createOfLast
4444

4545
-- * Pinning & Unpinning
4646
, pin

core/src/Streamly/Internal/Data/Array.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Streamly.Internal.Data.Array
2020

2121
-- * Construction
2222
-- Monadic Folds
23-
, createLastOf
23+
, createOfLast
2424

2525
-- * Random Access
2626
-- , (!!)
@@ -207,13 +207,13 @@ last = getIndexRev 0
207207

208208
-- XXX We should generate this from Ring.
209209

210-
-- | @createLastOf n@ folds a maximum of @n@ elements from the end of the input
210+
-- | @createOfLast n@ folds a maximum of @n@ elements from the end of the input
211211
-- stream to an 'Array'.
212212
--
213-
{-# INLINE createLastOf #-}
214-
createLastOf ::
213+
{-# INLINE createOfLast #-}
214+
createOfLast ::
215215
(Unbox a, MonadIO m) => Int -> Fold m a (Array a)
216-
createLastOf n
216+
createOfLast n
217217
| n <= 0 = fmap (const mempty) FL.drain
218218
| otherwise = unsafeFreeze <$> Fold step initial done done
219219

@@ -236,10 +236,10 @@ createLastOf n
236236
| i < n = RB.unsafeFoldRingM
237237
| otherwise = RB.unsafeFoldRingFullM
238238

239-
{-# DEPRECATED writeLastN "Please use createLastOf instead." #-}
239+
{-# DEPRECATED writeLastN "Please use createOfLast instead." #-}
240240
{-# INLINE writeLastN #-}
241241
writeLastN :: (Unbox a, MonadIO m) => Int -> Fold m a (Array a)
242-
writeLastN = createLastOf
242+
writeLastN = createOfLast
243243

244244
-------------------------------------------------------------------------------
245245
-- Random Access

core/src/Streamly/Internal/Data/Array/Generic.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Streamly.Internal.Data.Array.Generic
1414
, createOf
1515
, create
1616
, createWith
17-
, createLastOf
17+
, createOfLast
1818

1919
, fromStreamN
2020
, fromStream
@@ -267,14 +267,14 @@ getIndex i arr@Array {..} =
267267
-- >>> import Data.Function ((&))
268268
-- >>> :{
269269
-- Stream.fromList [1,2,3,4,5::Int]
270-
-- & Stream.scan (Array.createLastOf 2)
270+
-- & Stream.scan (Array.createOfLast 2)
271271
-- & Stream.fold Fold.toList
272272
-- :}
273273
-- [fromList [],fromList [1],fromList [1,2],fromList [2,3],fromList [3,4],fromList [4,5]]
274274
--
275-
{-# INLINE createLastOf #-}
276-
createLastOf :: MonadIO m => Int -> Fold m a (Array a)
277-
createLastOf n = FL.rmapM f (RB.createOf n)
275+
{-# INLINE createOfLast #-}
276+
createOfLast :: MonadIO m => Int -> Fold m a (Array a)
277+
createOfLast n = FL.rmapM f (RB.createOf n)
278278

279279
where
280280

core/src/Streamly/Internal/Data/Ring.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ advance rb ringHead =
152152
moveBy :: Int -> Ring a -> Int -> Int
153153
moveBy by rb ringHead = (ringHead + by) `mod1` ringCapacity rb
154154

155-
-- XXX Move the createLastOf from array module here.
155+
-- XXX Move the createOfLast from array module here.
156156
--
157157
-- | @createOf n@ is a rolling fold that keeps the last n elements of the stream
158158
-- in a ring array.

docs/Developer/optimization-guidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ specialize in the last phase, inlining in the last phase is left to
200200
the compiler. `INLINE [0]` may sound the same as `NOINLINE [0]`,
201201
however, it behaves differently because we ask the compiler to INLINE
202202
it compulsorily and it may not give us the desired results. The
203-
Data.Fold.createLastOf benchmark is one such case where `NOINLINE [0]`
203+
Data.Fold.createOfLast benchmark is one such case where `NOINLINE [0]`
204204
provides much better performance than `INLINE [0]`.
205205

206206
### NoSpecConstr

docs/User/HowTo/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ $(mkZippingType "ZipConcurrent" "app" True)
7979

8080
## Sliding Window
8181

82-
The `createLastOf` fold can be used to create a stream of sliding windows.
82+
The `createOfLast` fold can be used to create a stream of sliding windows.
8383

8484
```haskell docspec
8585
>>> import qualified Streamly.Data.Array as Array
8686
>>> :{
8787
Stream.fromList [1,2,3,4,5::Int]
88-
& Stream.scan (Array.createLastOf 2)
88+
& Stream.scan (Array.createOfLast 2)
8989
& Stream.fold Fold.toList
9090
:}
9191
[fromList [],fromList [1],fromList [1,2],fromList [2,3],fromList [3,4],fromList [4,5]]

test/Streamly/Test/Data/Array.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ testLastN =
6767
monadicIO $ do
6868
xs <- run
6969
$ fmap A.toList
70-
$ S.fold (A.createLastOf n)
70+
$ S.fold (A.createOfLast n)
7171
$ S.fromList list
7272
assert (xs == lastN n list)
7373

7474
testLastN_LN :: Int -> Int -> IO Bool
7575
testLastN_LN len n = do
7676
let list = [1..len]
77-
l1 <- fmap A.toList $ S.fold (A.createLastOf n) $ S.fromList list
77+
l1 <- fmap A.toList $ S.fold (A.createOfLast n) $ S.fromList list
7878
let l2 = lastN n list
7979
return $ l1 == l2
8080

@@ -239,12 +239,12 @@ main =
239239
it "middle" (unsafeWriteIndex [1..10] 5 0 `shouldReturn` True)
240240
it "last" (unsafeWriteIndex [1..10] 9 0 `shouldReturn` True)
241241
describe "Fold" $ do
242-
prop "createLastOf : 0 <= n <= len" testLastN
243-
describe "createLastOf boundary conditions" $ do
244-
it "createLastOf -1" (testLastN_LN 10 (-1) `shouldReturn` True)
245-
it "createLastOf 0" (testLastN_LN 10 0 `shouldReturn` True)
246-
it "createLastOf length" (testLastN_LN 10 10 `shouldReturn` True)
247-
it "createLastOf (length + 1)" (testLastN_LN 10 11 `shouldReturn` True)
242+
prop "createOfLast : 0 <= n <= len" testLastN
243+
describe "createOfLast boundary conditions" $ do
244+
it "createOfLast -1" (testLastN_LN 10 (-1) `shouldReturn` True)
245+
it "createOfLast 0" (testLastN_LN 10 0 `shouldReturn` True)
246+
it "createOfLast length" (testLastN_LN 10 10 `shouldReturn` True)
247+
it "createOfLast (length + 1)" (testLastN_LN 10 11 `shouldReturn` True)
248248
describe "Strip" $ do
249249
it "strip" (testStrip `shouldReturn` True)
250250
it "stripLeft" (testStripLeft `shouldReturn` True)

0 commit comments

Comments
 (0)