Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/Streamly/Benchmark/Data/Array/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ onArray
-> m (Stream Int)
onArray value f arr = S.fold (A.createOf value) $ f $ S.unfold A.reader arr

scanl' value n = composeN n $ onArray value $ S.scanl (Scanl.mkScanl (+) 0)
scanl' value n = composeN n $ onArray value $ S.scanl (Scanl.scanl' (+) 0)
scanl1' value n = composeN n $ onArray value $ Stream.scanl1' (+)
map value n = composeN n $ onArray value $ fmap (+1)
-- map n = composeN n $ A.map (+1)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Streamly/Benchmark/Data/MutArray.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ composeN n f x =

{-# INLINE scanl' #-}
scanl' :: MonadIO m => Int -> Int -> Stream Int -> m (Stream Int)
scanl' value n = composeN n $ onArray value $ Stream.scanl (Scanl.mkScanl (+) 0)
scanl' value n = composeN n $ onArray value $ Stream.scanl (Scanl.scanl' (+) 0)

{-# INLINE scanl1' #-}
scanl1' :: MonadIO m => Int -> Int -> Stream Int -> m (Stream Int)
Expand Down
14 changes: 7 additions & 7 deletions benchmark/Streamly/Benchmark/Data/Stream/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import Streamly.Internal.Data.Stream (Stream)
import qualified Streamly.Internal.Data.Fold as Fold
import qualified Streamly.Internal.Data.Pipe as Pipe
import qualified Streamly.Internal.Data.Scanl as Scanl
import qualified Streamly.Internal.Data.Scanr as Scanr
import qualified Streamly.Internal.Data.Scan as Scan
import qualified Streamly.Internal.Data.Stream as Stream

import Test.Tasty.Bench
Expand Down Expand Up @@ -433,7 +433,7 @@ foldl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> m b
foldl' f z = Stream.fold (Fold.foldl' f z)

scanl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> Stream m b
scanl' f z = Stream.scanl (Scanl.mkScanl f z)
scanl' f z = Stream.scanl (Scanl.scanl' f z)

{-# INLINE transformMapM #-}
transformMapM ::
Expand All @@ -449,7 +449,7 @@ scanMapM ::
=> Int
-> Stream m Int
-> m ()
scanMapM n = composeN n $ Stream.scanr (Scanr.functionM return)
scanMapM n = composeN n $ Stream.scanr (Scan.functionM return)

{-# INLINE transformComposeMapM #-}
transformComposeMapM ::
Expand All @@ -472,8 +472,8 @@ scanComposeMapM ::
scanComposeMapM n =
composeN n $
Stream.scanr
(Scanr.functionM (\x -> return (x + 1)) `Scanr.compose`
Scanr.functionM (\x -> return (x + 2)))
(Scan.functionM (\x -> return (x + 1)) `Scan.compose`
Scan.functionM (\x -> return (x + 2)))

{-# INLINE transformTeeMapM #-}
transformTeeMapM ::
Expand All @@ -496,8 +496,8 @@ scanTeeMapM ::
scanTeeMapM n =
composeN n $
Stream.scanr
(Scanr.teeWith (+) (Scanr.functionM (\x -> return (x + 1)))
(Scanr.functionM (\x -> return (x + 2))))
(Scan.teeWith (+) (Scan.functionM (\x -> return (x + 1)))
(Scan.functionM (\x -> return (x + 2))))

{-
{-# INLINE transformZipMapM #-}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Streamly/Benchmark/Data/Stream/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ o_1_space_mappingX4 value =
sieveScan :: Monad m => Stream m Int -> Stream m Int
sieveScan =
Stream.mapMaybe snd
. Stream.scanl (Scanl.mkScanlM (\(primes, _) n -> do
. Stream.scanl (Scanl.scanlM' (\(primes, _) n -> do
return $
let ps = takeWhile (\p -> p * p <= n) primes
in if all (\p -> n `mod` p /= 0) ps
Expand Down
26 changes: 13 additions & 13 deletions core/src/Streamly/Data/Scanr.hs → core/src/Streamly/Data/Scan.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-- |
-- Module : Streamly.Data.Scanr
-- Module : Streamly.Data.Scan
-- Copyright : (c) 2019 Composewell Technologies
-- License : BSD3
-- Maintainer : streamly@composewell.com
-- Stability : experimental
-- Portability : GHC
--
-- 'Scanr' is a right scan. The 'Scanr' type facilitates a stateful
-- 'Scan' is a right scan. The 'Scan' type facilitates a stateful
-- transformation from a stream to another stream. In addition to simple
-- transformation of a stream, scans can also be used to split a stream into
-- multiple branches, perform different stateful transformations in each branch
Expand All @@ -21,14 +21,14 @@
-- stream.
--
-- >>> import qualified Streamly.Internal.Data.Fold as Fold
-- >>> import qualified Streamly.Internal.Data.Scanr as Scanr
-- >>> import qualified Streamly.Internal.Data.Scan as Scan
-- >>> import qualified Streamly.Internal.Data.Stream as Stream
-- >>> import Data.Function ((&))
--
-- >>> scan1 = Scanr.function (\x -> x * x)
-- >>> scan2 = Scanr.function (\x -> 3 * x)
-- >>> scan3 = Scanr.teeWith (+) scan1 scan2 -- Compute x^2 + 3x
-- >>> scan4 = Scanr.compose scan1 scan3 -- compute x^2 then pass it to scan3
-- >>> scan1 = Scan.function (\x -> x * x)
-- >>> scan2 = Scan.function (\x -> 3 * x)
-- >>> scan3 = Scan.teeWith (+) scan1 scan2 -- Compute x^2 + 3x
-- >>> scan4 = Scan.compose scan1 scan3 -- compute x^2 then pass it to scan3
--
-- >>> :{
-- main =
Expand All @@ -53,10 +53,10 @@
-- one input it can produce at most one output, in other words it can shrink or
-- filter a stream but it cannot expand it.
--
-- == Scanr vs Scanl
-- == Scan vs Scanl
--
-- 'Scanr' is a right scan, and 'Scanl' is a left scan. 'Scanr' is to 'Stream'
-- as 'Scanl' is to 'Fold'. 'Scanr' is for composing producer stream
-- 'Scan' is a right scan, and 'Scanl' is a left scan. 'Scan' is to 'Stream'
-- as 'Scanl' is to 'Fold'. 'Scan' is for composing producer stream
-- transformations whereas 'Scanl' is for composing consumer stream
-- transformations.
--
Expand All @@ -72,10 +72,10 @@
-- @distribute@: Each input is supplied to all scans and the outputs are zipped
-- or merged.
--
module Streamly.Data.Scanr
module Streamly.Data.Scan
(
-- * Type
Scanr
Scan

-- * Primitive Scans
, identity
Expand All @@ -91,5 +91,5 @@ module Streamly.Data.Scanr
)
where

import Streamly.Internal.Data.Scanr
import Streamly.Internal.Data.Scan
import Prelude hiding (filter)
17 changes: 12 additions & 5 deletions core/src/Streamly/Data/Scanl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ module Streamly.Data.Scanl
Scanl -- (..)

-- * Constructors
, mkScanl
, mkScanlM
, mkScanl1
, mkScanl1M
, scanl'
, scanlM'
, scanl1'
, scanl1M'
, mkScanr

-- * Scans
Expand Down Expand Up @@ -141,7 +141,7 @@ module Streamly.Data.Scanl
-- | Transformations that combine two or more scans.

-- ** Scanning
, scanl
, compose
, postscanl
, postscanlMaybe

Expand Down Expand Up @@ -173,6 +173,13 @@ module Streamly.Data.Scanl
-- ** Key-value Scanners
, demux
, demuxIO

-- * Deprecated
, scanl
, mkScanl
, mkScanlM
, mkScanl1
, mkScanl1M
)
where

Expand Down
12 changes: 6 additions & 6 deletions core/src/Streamly/Data/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ module Streamly.Data.Stream
-- ** Scanning By 'Scanl'
-- | Useful idioms:
--
-- >>> scanl' f z = Stream.scanl (Scanl.mkScanl f z)
-- >>> scanlM' f z = Stream.scanl (Scanl.mkScanlM f z)
-- >>> postscanl' f z = Stream.postscanl (Scanl.mkScanl f z)
-- >>> postscanlM' f z = Stream.postscanl (Scanl.mkScanlM f z)
-- >>> scanl1' f = Stream.catMaybes . Stream.scanl (Scanl.mkScanl1 f)
-- >>> scanl1M' f = Stream.catMaybes . Stream.scanl (Scanl.mkScanl1M f)
-- >>> scanl' f z = Stream.scanl (Scanl.scanl' f z)
-- >>> scanlM' f z = Stream.scanl (Scanl.scanlM' f z)
-- >>> postscanl' f z = Stream.postscanl (Scanl.scanl' f z)
-- >>> postscanlM' f z = Stream.postscanl (Scanl.scanlM' f z)
-- >>> scanl1' f = Stream.catMaybes . Stream.scanl (Scanl.scanl1' f)
-- >>> scanl1M' f = Stream.catMaybes . Stream.scanl (Scanl.scanl1M' f)
, scanl
, postscanl
-- XXX postscan1 can be implemented using Monoids or Refolds.
Expand Down
10 changes: 5 additions & 5 deletions core/src/Streamly/Internal/Data/Fold/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ fromScanl (Scanl step initial extract final) = Fold step initial extract final
--
{-# INLINE foldl' #-}
foldl' :: Monad m => (b -> a -> b) -> b -> Fold m a b
foldl' step = fromScanl . Scanl.mkScanl step
foldl' step = fromScanl . Scanl.scanl' step

-- | Make a fold from a left fold style monadic step function and initial value
-- of the accumulator.
Expand All @@ -639,15 +639,15 @@ foldl' step = fromScanl . Scanl.mkScanl step
--
{-# INLINE foldlM' #-}
foldlM' :: Monad m => (b -> a -> m b) -> m b -> Fold m a b
foldlM' step = fromScanl . Scanl.mkScanlM step
foldlM' step = fromScanl . Scanl.scanlM' step

-- | Make a strict left fold, for non-empty streams, using first element as the
-- starting value. Returns Nothing if the stream is empty.
--
-- /Pre-release/
{-# INLINE foldl1' #-}
foldl1' :: Monad m => (a -> a -> a) -> Fold m a (Maybe a)
foldl1' = fromScanl . Scanl.mkScanl1
foldl1' = fromScanl . Scanl.scanl1'

-- | Like 'foldl1\'' but with a monadic step function.
--
Expand All @@ -662,7 +662,7 @@ foldlM1' = foldl1M'
-- /Pre-release/
{-# INLINE foldl1M' #-}
foldl1M' :: Monad m => (a -> a -> m a) -> Fold m a (Maybe a)
foldl1M' = fromScanl . Scanl.mkScanl1M
foldl1M' = fromScanl . Scanl.scanl1M'

{-
data FromScan s b = FromScanInit !s | FromScanGo !s !b
Expand Down Expand Up @@ -775,7 +775,7 @@ foldrM' g = fromScanl . Scanl.mkScanrM g
--
{-# INLINE foldt' #-}
foldt' :: Monad m => (s -> a -> Step s b) -> Step s b -> (s -> b) -> Fold m a b
foldt' step initial = fromScanl . Scanl.mkScant step initial
foldt' step initial = fromScanl . Scanl.scant' step initial

-- | Make a terminating fold with an effectful step function and initial state,
-- and a state extraction function.
Expand Down
10 changes: 5 additions & 5 deletions core/src/Streamly/Internal/Data/Pipe/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Streamly.Internal.Data.Pipe.Type

-- * From folds
, fromStream
, fromScanr
, fromScan
, fromFold
, scanFold

Expand All @@ -41,7 +41,7 @@ import Data.Kind (Type)
#endif
import Fusion.Plugin.Types (Fuse(..))
import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.Scanr (Scanr(..))
import Streamly.Internal.Data.Scan (Scan(..))
import Streamly.Internal.Data.Stream.Type (Stream(..))
-- import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
import Streamly.Internal.Data.SVar.Type (defState)
Expand Down Expand Up @@ -714,9 +714,9 @@ fromStream (Stream step state) = Pipe consume produce ()
Stream.Skip s -> SkipP s
Stream.Stop -> Stop

{-# INLINE fromScanr #-}
fromScanr :: Monad m => Scanr m a b -> Pipe m a b
fromScanr (Scanr step initial) = Pipe consume undefined initial
{-# INLINE fromScan #-}
fromScan :: Monad m => Scan m a b -> Pipe m a b
fromScan (Scan step initial) = Pipe consume undefined initial

where

Expand Down
Loading
Loading