on master help sign in
Rename head to one (#1887)
05eb489Ranjeet Ranjan
core/src/Streamly/Data/Fold.hs+4−3
@@ -29,10 +29,10 @@
29-- >>> Data.List.foldl' (+) 0 [1..100]
29-- >>> Data.List.foldl' (+) 0 [1..100]
30-- 5050
30-- 5050
31--
31--
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
33-- terminate on an infinite stream:
33-- terminate on an infinite stream:
34--
34--
35−-- >>> Stream.fold Fold.head $ Stream.fromList [1..]
35+-- >>> Stream.fold Fold.one $ Stream.fromList [1..]
36-- Just 1
36-- Just 1
37--
37--
38-- The above example is similar to the following right fold:
38-- The above example is similar to the following right fold:
@@ -173,7 +173,7 @@ module Streamly.Data.Fold
173 -- | These are much like lazy right folds.
173 -- | These are much like lazy right folds.
174
174
175 , index
175 , index
176− , head
176+ , one
177 , find
177 , find
178 , lookup
178 , lookup
179 , findIndex
179 , findIndex
@@ -266,6 +266,7 @@ module Streamly.Data.Fold
266 , concatMap
266 , concatMap
267
267
268 -- * Deprecated
268 -- * Deprecated
269+ , head
269 , sequence
270 , sequence
270 , mapM
271 , mapM
271 , variance
272 , variance
core/src/Streamly/Data/Fold/Tee.hs+1−1
@@ -27,7 +27,7 @@
27-- instances of the output types:
27-- instances of the output types:
28--
28--
29-- >>> import Data.Monoid (Sum(..))
29-- >>> import Data.Monoid (Sum(..))
30−-- >>> t = Tee Fold.head <> Tee Fold.last
30+-- >>> t = Tee Fold.one <> Tee Fold.last
31-- >>> Stream.fold (toFold t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)
31-- >>> Stream.fold (toFold t) (fmap Sum $ Stream.enumerateFromTo 1.0 100.0)
32-- Just (Sum {getSum = 101.0})
32-- Just (Sum {getSum = 101.0})
33--
33--
core/src/Streamly/Internal/Data/Array/Unboxed.hs+1−1
@@ -323,7 +323,7 @@ findIndicesOf = undefined
323
323
324{-
324{-
325findIndexOf :: (a -> Bool) -> Array a -> Maybe Int
325findIndexOf :: (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)
327
327
328find :: (a -> Bool) -> Array a -> Bool
328find :: (a -> Bool) -> Array a -> Bool
329find = Unfold.fold Fold.null . Stream.unfold (findIndicesOf p)
329find = 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
120 -- ** Terminating Folds
120 -- ** Terminating Folds
121 -- Element folds. Terminate after inspecting one element. All these can be
121 -- Element folds. Terminate after inspecting one element. All these can be
122 -- implemented in terms of the 'maybe' fold.
122 -- implemented in terms of the 'maybe' fold.
123− , head
124 , one
123 , one
125 , null
124 , null
126 , satisfy
125 , satisfy
@@ -319,6 +318,7 @@ module Streamly.Internal.Data.Fold
319 , finish
318 , finish
320
319
321 -- * Deprecated
320 -- * Deprecated
321+ , head
322 , sequence
322 , sequence
323 , mapM
323 , mapM
324 , variance
324 , variance
@@ -1265,7 +1265,7 @@ one = maybe Just
1265-- >>> head = Fold.one
1265-- >>> head = Fold.one
1266--
1266--
1267-- @since 0.7.0
1267-- @since 0.7.0
1268−-- {-# DEPRECATED head "Please use \"one\" instead" #-}
1268+{-# DEPRECATED head "Please use \"one\" instead" #-}
1269{-# INLINE head #-}
1269{-# INLINE head #-}
1270head :: Monad m => Fold m a (Maybe a)
1270head :: Monad m => Fold m a (Maybe a)
1271head = one
1271head = one
@@ -1366,7 +1366,7 @@ elemIndex a = findIndex (a ==)
1366
1366
1367-- | Return 'True' if the input stream is empty.
1367-- | Return 'True' if the input stream is empty.
1368--
1368--
1369−-- > null = fmap isJust Fold.head
1369+-- > null = fmap isJust Fold.one
1370--
1370--
1371-- @since 0.7.0
1371-- @since 0.7.0
1372{-# INLINE null #-}
1372{-# INLINE null #-}
core/src/Streamly/Internal/Data/Fold/Type.hs+1−1
@@ -1053,7 +1053,7 @@ data ConcatMapState m sa a c
1053-- elements that we have to add, then:
1053-- elements that we have to add, then:
1054--
1054--
1055-- >>> import Data.Maybe (fromJust)
1055-- >>> import Data.Maybe (fromJust)
1056−-- >>> count = fmap fromJust Fold.head
1056+-- >>> count = fmap fromJust Fold.one
1057-- >>> total n = Fold.take n Fold.sum
1057-- >>> total n = Fold.take n Fold.sum
1058-- >>> Stream.fold (Fold.concatMap total count) $ Stream.fromList [10,9..1]
1058-- >>> Stream.fold (Fold.concatMap total count) $ Stream.fromList [10,9..1]
1059-- 45
1059-- 45
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+1−1
@@ -427,7 +427,7 @@ null = D.null . toStreamD
427-- | Extract the first element of the stream, if any.
427-- | Extract the first element of the stream, if any.
428--
428--
429-- > head = (!! 0)
429-- > head = (!! 0)
430−-- > head = Stream.fold Fold.head
430+-- > head = Stream.fold Fold.one
431--
431--
432-- @since 0.1.0
432-- @since 0.1.0
433{-# INLINE head #-}
433{-# INLINE head #-}
src/Streamly/Internal/Data/Stream/IsStream/Top.hs+3−3
@@ -71,7 +71,7 @@ import qualified Streamly.Internal.Data.Array as Array
71 (fromStream, length, toStream)
71 (fromStream, length, toStream)
72import qualified Streamly.Data.Array.Unboxed.Mut as MA
72import qualified Streamly.Data.Array.Unboxed.Mut as MA
73import qualified Streamly.Internal.Data.Fold as Fold
73import qualified Streamly.Internal.Data.Fold as Fold
74− (head, last, toStream, toStreamRev)
74+ (one, last, toStream, toStreamRev)
75import qualified Streamly.Internal.Data.Parser as Parser
75import qualified Streamly.Internal.Data.Parser as Parser
76 (groupByRollingEither)
76 (groupByRollingEither)
77import qualified Streamly.Internal.Data.Stream.IsStream.Lift as Stream
77import qualified Streamly.Internal.Data.Stream.IsStream.Lift as Stream
@@ -132,7 +132,7 @@ sampleIntervalEnd n = Stream.catMaybes . Stream.intervalsOf n Fold.last
132-- | Like 'sampleInterval' but samples at the beginning of the time window.
132-- | Like 'sampleInterval' but samples at the beginning of the time window.
133--
133--
134-- @
134-- @
135−-- sampleIntervalStart n = Stream.catMaybes . Stream.intervalsOf n Fold.head
135+-- sampleIntervalStart n = Stream.catMaybes . Stream.intervalsOf n Fold.one
136-- @
136-- @
137--
137--
138-- /Pre-release/
138-- /Pre-release/
@@ -140,7 +140,7 @@ sampleIntervalEnd n = Stream.catMaybes . Stream.intervalsOf n Fold.last
140{-# INLINE sampleIntervalStart #-}
140{-# INLINE sampleIntervalStart #-}
141sampleIntervalStart :: (IsStream t, MonadAsync m, Functor (t m)) =>
141sampleIntervalStart :: (IsStream t, MonadAsync m, Functor (t m)) =>
142 Double -> t m a -> t m a
142 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
144
144
145data BurstState t x =
145data BurstState t x =
146 BurstNone
146 BurstNone
test/Streamly/Test/Data/Fold.hs+2−2
@@ -70,7 +70,7 @@ rollingHashFirstN =
70 assert $ a == b
70 assert $ a == b
71
71
72head :: [Int] -> Expectation
72head :: [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
74
74
75headl :: [a] -> Maybe a
75headl :: [a] -> Maybe a
76headl [] = Nothing
76headl [] = Nothing
@@ -582,7 +582,7 @@ many =
582
582
583foldBreak :: [Int] -> Property
583foldBreak :: [Int] -> Property
584foldBreak ls = monadicIO $ do
584foldBreak 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)
586 rests <- run $ Stream.fold Fold.toList rest
586 rests <- run $ Stream.fold Fold.toList rest
587 assert (mbh == headl ls)
587 assert (mbh == headl ls)
588 listEquals (==) rests (taill ls)
588 listEquals (==) rests (taill ls)