withdependencies-0.3.1: Run computations that depend on one or more elements in a stream.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Dependency

Description

This module is a glorified wrapper over lookup. It let you define computations in an applicative way that "require" some optional values, defined by an identifier.

Once defined, it is possible to extract the list of identifiers, and also to evaluate the computation.

let computation = ( (+) <$> require "a" <*> require "b" )
> computeRequire M.empty computation :: Maybe Int
Nothing
> computeRequire (M.fromList [("a", 12), ("b", 15)]) computation :: Maybe Int
Just 27
> computeRequire (M.fromList [("a", 12), ("c", 15)]) computation :: Maybe Int
Nothing
Synopsis

Documentation

data Require identifier content a Source #

The main data type, used to model a computation that requires a list of named parameters (the "identifier"), that are linked to a "content", and that will yield a result of type "a".

Instances

Instances details
Profunctor (Require identifier) Source # 
Instance details

Defined in Control.Dependency

Methods

dimap :: (a -> b) -> (c -> d) -> Require identifier b c -> Require identifier a d #

lmap :: (a -> b) -> Require identifier b c -> Require identifier a c #

rmap :: (b -> c) -> Require identifier a b -> Require identifier a c #

(#.) :: forall a b c q. Coercible c b => q b c -> Require identifier a b -> Require identifier a c #

(.#) :: forall a b c q. Coercible b a => Require identifier b c -> q a b -> Require identifier a c #

Alternative (Require identifier content) Source # 
Instance details

Defined in Control.Dependency

Methods

empty :: Require identifier content a #

(<|>) :: Require identifier content a -> Require identifier content a -> Require identifier content a #

some :: Require identifier content a -> Require identifier content [a] #

many :: Require identifier content a -> Require identifier content [a] #

Applicative (Require identifier content) Source # 
Instance details

Defined in Control.Dependency

Methods

pure :: a -> Require identifier content a #

(<*>) :: Require identifier content (a -> b) -> Require identifier content a -> Require identifier content b #

liftA2 :: (a -> b -> c) -> Require identifier content a -> Require identifier content b -> Require identifier content c #

(*>) :: Require identifier content a -> Require identifier content b -> Require identifier content b #

(<*) :: Require identifier content a -> Require identifier content b -> Require identifier content a #

Functor (Require identifier content) Source # 
Instance details

Defined in Control.Dependency

Methods

fmap :: (a -> b) -> Require identifier content a -> Require identifier content b #

(<$) :: a -> Require identifier content b -> Require identifier content a #

require :: Eq identifier => identifier -> Require identifier content content Source #

This operator let you "require" a value in a computation.

requireFilter :: (identifier -> Bool) -> Require identifier content (identifier, content) Source #

guardResult Source #

Arguments

:: (result -> Bool)

predicate

-> Require identifier content result 
-> Require identifier content result 

Will drop the result unless the predicate is true.

computeRequire :: forall identifier content f a. (Ord identifier, Eq identifier, Monad f, Alternative f) => [(identifier, content)] -> Require identifier content a -> f a Source #

Evaluate a computation, given a map of key/values for possible parameters.

computeRequireIntermediate :: forall identifier content f a. (Ord identifier, Eq identifier, Monad f, Alternative f) => [(identifier, content)] -> Require identifier content a -> f a Source #

Evaluate a computation, given a map of key/values for possible parameters. Returns an empty result when alternatives are present and the first choice failed.

isComputable :: (Ord identifier, Eq identifier) => Set identifier -> Require identifier content a -> Bool Source #

Checks if a computation can be completed given a set of known identifiers.

triggersAnalyzer :: identifier -> Require identifier content a -> Bool Source #