on master help sign in
Rename head to one (#1887)
commit05eb489fd3ced785dc4e40ed07f9e3b180ef0549 authorRanjeet Ranjan <ranjeetr@composewell.com> dateTue 4 Oct 2022, 17:00 (4 years ago) parenta47303e
8 files changed+16−15
core/src/Streamly/Data/Fold.hs+4−3 core/src/Streamly/Data/Fold/Tee.hs+1−1 core/src/Streamly/Internal/Data/Array/Unboxed.hs+1−1 core/src/Streamly/Internal/Data/Fold.hs+3−3 core/src/Streamly/Internal/Data/Fold/Type.hs+1−1 src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+1−1 src/Streamly/Internal/Data/Stream/IsStream/Top.hs+3−3 test/Streamly/Test/Data/Fold.hs+2−2
core/src/Streamly/Data/Fold.hs+4−3
@@ -29,10 +29,10 @@
2929-- >>> Data.List.foldl' (+) 0 [1..100]
3030-- 5050
3131--
32−-- 'Fold's have an early termination capability e.g. the 'head' fold would
32+-- 'Fold's have an early termination capability e.g. the 'one' fold would
3333-- terminate on an infinite stream:
3434--
35−-- >>> Stream.fold Fold.head $ Stream.fromList [1..]
35+-- >>> Stream.fold Fold.one $ Stream.fromList [1..]
3636-- Just 1
3737--
3838-- The above example is similar to the following right fold:
@@ -173,7 +173,7 @@ module Streamly.Data.Fold
173173 -- | These are much like lazy right folds.
174174
175175 , index
176− , head
176+ , one
177177 , find
178178 , lookup
179179 , findIndex
@@ -266,6 +266,7 @@ module Streamly.Data.Fold
266266 , concatMap
267267
268268 -- * Deprecated
269+ , head
269270 , sequence
270271 , mapM
271272 , variance
core/src/Streamly/Data/Fold/Tee.hs+1−1
@@ -27,7 +27,7 @@
2727-- instances of the output types:
2828--
2929-- >>> import Data.Monoid (Sum(..))
30−-- >>> t = Tee Fold.head <> Tee Fold.last
30+-- >>> t = Tee Fold.one <> Tee Fold.last
3131-- >>> Stream.fold (toFold t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)
3232-- Just (Sum {getSum = 101.0})
3333--
core/src/Streamly/Internal/Data/Array/Unboxed.hs+1−1
@@ -323,7 +323,7 @@ findIndicesOf = undefined
323323
324324{-
325325findIndexOf :: (a -> Bool) -> Array a -> Maybe Int
326−findIndexOf p = Unfold.fold Fold.head . Stream.unfold (findIndicesOf p)
326+findIndexOf p = Unfold.fold Fold.one . Stream.unfold (findIndicesOf p)
327327
328328find :: (a -> Bool) -> Array a -> Bool
329329find = Unfold.fold Fold.null . Stream.unfold (findIndicesOf p)
core/src/Streamly/Internal/Data/Fold.hs+3−3
@@ -120,7 +120,6 @@ module Streamly.Internal.Data.Fold
120120 -- ** Terminating Folds
121121 -- Element folds. Terminate after inspecting one element. All these can be
122122 -- implemented in terms of the 'maybe' fold.
123− , head
124123 , one
125124 , null
126125 , satisfy
@@ -319,6 +318,7 @@ module Streamly.Internal.Data.Fold
319318 , finish
320319
321320 -- * Deprecated
321+ , head
322322 , sequence
323323 , mapM
324324 , variance
@@ -1265,7 +1265,7 @@ one = maybe Just
12651265-- >>> head = Fold.one
12661266--
12671267-- @since 0.7.0
1268−-- {-# DEPRECATED head "Please use \"one\" instead" #-}
1268+{-# DEPRECATED head "Please use \"one\" instead" #-}
12691269{-# INLINE head #-}
12701270head :: Monad m => Fold m a (Maybe a)
12711271head = one
@@ -1366,7 +1366,7 @@ elemIndex a = findIndex (a ==)
13661366
13671367-- | Return 'True' if the input stream is empty.
13681368--
1369−-- > null = fmap isJust Fold.head
1369+-- > null = fmap isJust Fold.one
13701370--
13711371-- @since 0.7.0
13721372{-# INLINE null #-}
core/src/Streamly/Internal/Data/Fold/Type.hs+1−1
@@ -1053,7 +1053,7 @@ data ConcatMapState m sa a c
10531053-- elements that we have to add, then:
10541054--
10551055-- >>> import Data.Maybe (fromJust)
1056−-- >>> count = fmap fromJust Fold.head
1056+-- >>> count = fmap fromJust Fold.one
10571057-- >>> total n = Fold.take n Fold.sum
10581058-- >>> Stream.fold (Fold.concatMap total count) $ Stream.fromList [10,9..1]
10591059-- 45
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+1−1
@@ -427,7 +427,7 @@ null = D.null . toStreamD
427427-- | Extract the first element of the stream, if any.
428428--
429429-- > head = (!! 0)
430−-- > head = Stream.fold Fold.head
430+-- > head = Stream.fold Fold.one
431431--
432432-- @since 0.1.0
433433{-# INLINE head #-}
src/Streamly/Internal/Data/Stream/IsStream/Top.hs+3−3
@@ -71,7 +71,7 @@ import qualified Streamly.Internal.Data.Array as Array
7171 (fromStream, length, toStream)
7272import qualified Streamly.Data.Array.Unboxed.Mut as MA
7373import qualified Streamly.Internal.Data.Fold as Fold
74− (head, last, toStream, toStreamRev)
74+ (one, last, toStream, toStreamRev)
7575import qualified Streamly.Internal.Data.Parser as Parser
7676 (groupByRollingEither)
7777import qualified Streamly.Internal.Data.Stream.IsStream.Lift as Stream
@@ -132,7 +132,7 @@ sampleIntervalEnd n = Stream.catMaybes . Stream.intervalsOf n Fold.last
132132-- | Like 'sampleInterval' but samples at the beginning of the time window.
133133--
134134-- @
135−-- sampleIntervalStart n = Stream.catMaybes . Stream.intervalsOf n Fold.head
135+-- sampleIntervalStart n = Stream.catMaybes . Stream.intervalsOf n Fold.one
136136-- @
137137--
138138-- /Pre-release/
@@ -140,7 +140,7 @@ sampleIntervalEnd n = Stream.catMaybes . Stream.intervalsOf n Fold.last
140140{-# INLINE sampleIntervalStart #-}
141141sampleIntervalStart :: (IsStream t, MonadAsync m, Functor (t m)) =>
142142 Double -> t m a -> t m a
143−sampleIntervalStart n = Stream.catMaybes . Stream.intervalsOf n Fold.head
143+sampleIntervalStart n = Stream.catMaybes . Stream.intervalsOf n Fold.one
144144
145145data BurstState t x =
146146 BurstNone
test/Streamly/Test/Data/Fold.hs+2−2
@@ -70,7 +70,7 @@ rollingHashFirstN =
7070 assert $ a == b
7171
7272head :: [Int] -> Expectation
73−head ls = Stream.fold Fold.head (Stream.fromList ls) `shouldReturn` headl ls
73+head ls = Stream.fold Fold.one (Stream.fromList ls) `shouldReturn` headl ls
7474
7575headl :: [a] -> Maybe a
7676headl [] = Nothing
@@ -582,7 +582,7 @@ many =
582582
583583foldBreak :: [Int] -> Property
584584foldBreak ls = monadicIO $ do
585− (mbh, rest) <- run $ Stream.foldBreak Fold.head (Stream.fromList ls)
585+ (mbh, rest) <- run $ Stream.foldBreak Fold.one (Stream.fromList ls)
586586 rests <- run $ Stream.fold Fold.toList rest
587587 assert (mbh == headl ls)
588588 listEquals (==) rests (taill ls)