Module

Run.Streaming

Package
purescript-run
Repository
natefaubion/purescript-run

This module defines primitive combinators for both push and pull streams.

map ∷ ∀ x y r a. (x → y) → Transformer r x y a
map f = forever do
  x ← await
  yield (f x)

take ∷ ∀ x r. Int → Transformer r x x Unit
take n
  | n <= 0    = pure unit
  | otherwise = do
      await >>= yield
      take (n - 1)

naturals ∷ ∀ r a. Producer r Int a
naturals = go 1
  where
  go n = do
    yield n
    go (n + 1)

toConsole ∷ ∀ eff r a. Consumer (base ∷ BaseEff (console ∷ CONSOLE | eff) | r) String a
toConsole = forever (await >>= log >>> liftBase)

main ∷ Eff (console ∷ CONSOLE) Unit
main = runBase $
  naturals
  !> take 100
  !> map show
  !> toConsole

#Step Source

data Step i o a

Constructors

Instances

#YIELD Source

type YIELD a = FProxy (Step Unit a)

#_yield Source

_yield :: SProxy "yield"

#yield Source

yield :: forall r o. o -> Run (yield :: YIELD o | r) Unit

#AWAIT Source

type AWAIT a = FProxy (Step a Unit)

#_await Source

_await :: SProxy "await"

#await Source

await :: forall r i. Run (await :: AWAIT i | r) i

#Resume Source

data Resume r a i o

Constructors

Instances

#Producer Source

type Producer r o a = Run (yield :: YIELD o | r) a

#Consumer Source

type Consumer r i a = Run (await :: AWAIT i | r) a

#Transformer Source

type Transformer r i o a = Run (await :: AWAIT i, yield :: YIELD o | r) a

#runStep Source

runStep :: forall a r2 r1 o i sym. RowCons sym (FProxy (Step i o)) r1 r2 => IsSymbol sym => SProxy sym -> Run r2 a -> Run r1 (Resume r1 a i o)

#runProducer Source

runProducer :: forall o a r. Producer r o a -> Run r (Resume r a Unit o)

#runConsumer Source

runConsumer :: forall i a r. Consumer r i a -> Run r (Resume r a i Unit)

#fuse Source

fuse :: forall a r o i. Resume r a i o -> Resume r a o i -> Run r a

#push Source

push :: forall o a r. Producer r o a -> Consumer r o a -> Run r a

#(!>) Source

Operator alias for Run.Streaming.push (left-associative / precedence 6)

#pull Source

pull :: forall o a r. Consumer r o a -> Producer r o a -> Run r a

#(!<) Source

Operator alias for Run.Streaming.pull (right-associative / precedence 6)