churros-0.1.0.0: Churros: Channel/Arrow based streaming computation library.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Churro.Types

Description

Datatypes and definitions used by Churro library.

Expand instances for additional documentation!

Synopsis

Documentation

We import the library for testing, although this would be a circular import in the module itself.

>>> import Control.Churro

Data, Classes and Instances

data Churro t i o Source #

The core datatype for the library. Parameterst, i and o represent the transport, input and output types respectively.

When building a program by composing Churros, the output Transport of one Churro is fed into the input Transports of other Churros.

Constructors

Churro 

Fields

Instances

Instances details
Transport t => Arrow (Churro t) Source #

The Arrow instance allows for building non-cyclic directed graphs of churros.

The arr method allows for the creation of a that maps items with a pure function. This is equivalent to `fmap f id`.

>>> :set -XArrows
>>> :{
let sect  = process $ \x@(_x,_y,z) -> print x >> return z
    graph =
      proc i -> do
        j <- arr succ  -< i
        k <- arr show  -< j
        l <- arr succ  -< j
        m <- arr (> 5) -< j
        n <- sect      -< (k,l,m)
        o <- arr not   -< n
        sinkPrint      -< o
in
runWaitChan $ sourceList [1,5,30] >>> graph
:}
("2",3,False)
("6",7,True)
("31",32,True)
True
False
False

The other Arrow methods are also usable:

>>> runWaitChan $ pure 1 >>> (arr show &&& arr succ) >>> sinkPrint
("1",2)
Instance details

Defined in Control.Churro.Types

Methods

arr :: (b -> c) -> Churro t b c #

first :: Churro t b c -> Churro t (b, d) (c, d) #

second :: Churro t b c -> Churro t (d, b) (d, c) #

(***) :: Churro t b c -> Churro t b' c' -> Churro t (b, b') (c, c') #

(&&&) :: Churro t b c -> Churro t b c' -> Churro t b (c, c') #

Transport t => Category (Churro t :: Type -> Type -> Type) Source #

The Category instance allows for the creation of Churro pipelines.

All other examples of the form `a >>> b` use this instance.

The id method creates a passthrough arrow. There isn't usually a reason to use id directly as it has no effect:

>>> runWaitChan $ pure 1 >>> id >>> id >>> id >>> sinkPrint
1
Instance details

Defined in Control.Churro.Types

Methods

id :: forall (a :: k). Churro t a a #

(.) :: forall (b :: k) (c :: k) (a :: k). Churro t b c -> Churro t a b -> Churro t a c #

Transport t => Functor (Churro t i) Source #

Covariant functor instance for Churro - Maps over the output.

>>> let s = sourceList [1,2]
>>> runWaitChan $ s >>> sinkPrint
1
2
>>> runWaitChan $ fmap succ s >>> sinkPrint
2
3
Instance details

Defined in Control.Churro.Types

Methods

fmap :: (a -> b) -> Churro t i a -> Churro t i b #

(<$) :: a -> Churro t i b -> Churro t i a #

Transport t => Applicative (Churro t Void) Source #

The Applicative instance allows for pairwise composition of Churro pipelines. Once again this is covariat and the composition occurs on the output transports of the Churros.

The pure method allows for the creation of a Churro yielding a single item.

Instance details

Defined in Control.Churro.Types

Methods

pure :: a -> Churro t Void a #

(<*>) :: Churro t Void (a -> b) -> Churro t Void a -> Churro t Void b #

liftA2 :: (a -> b -> c) -> Churro t Void a -> Churro t Void b -> Churro t Void c #

(*>) :: Churro t Void a -> Churro t Void b -> Churro t Void b #

(<*) :: Churro t Void a -> Churro t Void b -> Churro t Void a #

class Transport t where Source #

The transport method is abstracted via the Transport class

This allows use of pure or impure channels, such as:

  • Chan (Included in Chan)
  • TChan
  • Seq
  • Various buffered options

Transports used in conjunction with Churros wrap items in Maybe so that once a source has been depleted it can signal completion with a Nothing item.

Methods

flex Source #

Arguments

:: IO (t a)

Create a new Transport

yank Source #

Arguments

:: t a 
-> IO a

Yank an item of the Transport

yeet Source #

Arguments

:: t a 
-> a 
-> IO ()

Yeet an item onto the Transport

Instances

Instances details
Transport Chan Source # 
Instance details

Defined in Control.Churro.Transport.Chan

Methods

flex :: IO (Chan a) Source #

yank :: Chan a -> IO a Source #

yeet :: Chan a -> a -> IO () Source #

Helpers

buildChurro :: Transport t => (t (Maybe i) -> t (Maybe o) -> IO ()) -> Churro t i o Source #

A helper to facilitate constructing a Churro that makes new input and output transports available for manipulation.

The manipulations performed are carried out in the async action associated with the Churro

yeetList :: (Foldable t1, Transport t2) => t2 a -> t1 a -> IO () Source #

Yeet all items from a list into a transport.

yankList :: Transport t => t (Maybe a) -> IO [a] Source #

Yank all items from a Raw transport into a list.

Won't terminate until the transport has been consumed.

yankAll :: Transport t => t (Maybe i) -> (i -> IO a) -> IO () Source #

Yank each item from a transport into a callback.

yankAll' :: Transport t => t (Maybe a) -> (Maybe a -> IO b) -> IO b Source #

Yank each raw item from a transport into a callback.

The items are wrapped in Maybes and when all items are yanked, Nothing is fed to the callback.

c2c :: Transport t => (a1 -> a2) -> t (Maybe a1) -> t (Maybe a2) -> IO () Source #

Yank then Yeet each item from one Transport into another.

Raw items are used so Nothing should be Yeeted once the transport is depleted.

finally' :: IO b -> IO a -> IO a Source #

Flipped finally.