-- |
-- Module      : Streamly.Internal.Data.Stream.StreamD.Step
-- Copyright   : (c) 2018 Composewell Technologies
-- License     : BSD-3-Clause
-- Maintainer  : streamly@composewell.com
-- Stability   : experimental
-- Portability : GHC

module Streamly.Internal.Data.Stream.StreamD.Step
    (
    -- * The stream type
      Step (..)
    )
where

import Fusion.Plugin.Types (Fuse(..))

-- | A stream is a succession of 'Step's. A 'Yield' produces a single value and
-- the next state of the stream. 'Stop' indicates there are no more values in
-- the stream.
{-# ANN type Step Fuse #-}
data Step s a = Yield a s | Skip s | Stop

instance Functor (Step s) where
    {-# INLINE fmap #-}
    fmap :: (a -> b) -> Step s a -> Step s b
fmap a -> b
f (Yield a
x s
s) = b -> s -> Step s b
forall s a. a -> s -> Step s a
Yield (a -> b
f a
x) s
s
    fmap a -> b
_ (Skip s
s) = s -> Step s b
forall s a. s -> Step s a
Skip s
s
    fmap a -> b
_ Step s a
Stop = Step s b
forall s a. Step s a
Stop

{-
fromPure :: Monad m => a -> s -> m (Step s a)
fromPure a = return . Yield a

skip :: Monad m => s -> m (Step s a)
skip = return . Skip

stop :: Monad m => m (Step s a)
stop = return Stop
-}