withdependencies-0.2.3: Run computations that depend on one or more elements in a stream.

Safe HaskellSafe
LanguageHaskell2010

Data.Conduit.Require

Description

Runs computations depending on some values coming from a conduit. The computations are defined in applicative fashion.

test :: IO [Int]
test = inp =$ cnd $$ CL.consume
    where
        inp = sourceDirectory "/etc"
        cnd :: Conduit String IO Int
        cnd = withRequirement (map Once comps) id (fmap length . readFile)
        comps :: [Require String Int Int]
        comps = [ (+) <$> require "/etc/passwd" <*> require "/etc/passwd"
                , (-) <$> require "/etc/resolv.conf" <*> require "/etc/nonexistent"
                , require "/etc/hosts"
                ]

Synopsis

Documentation

withRequirement Source

Arguments

:: (Ord identifier, Eq identifier, Monad m, Functor m) 
=> [(RunMode, Require identifier content x)]

The list of dependent computations

-> (a -> identifier)

Extracting the identifier

-> (a -> m content)

Extracting the content, possibly with effects

-> Conduit a m x 

Given a stream of values, from which an identifier and a content can be extracted, runs a list of computation that depend on these.

Each computation's output is yielded downstream.

When all computations have been run, the conduit finishes processing.

data RunMode Source

This allows the user to parameter what happends once a requirement is fulfilled.

Constructors

Reset

The requirement will be reset, and can be run multiple times

Once

The requirement can only run once

Instances