tree-traversals-0.1.3.0: Functions and newtype wrappers for traversing Trees
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Applicative.Phases

Description

Defines Phases, an Applicative transformer for scheduling effects during different phases of execution.

Synopsis

Documentation

data Phases f a where Source #

An applicative transformer to organize effects into an arbitrary number of phases of execution.

Use now to schedule actions for the current phase of execution:

>>> say name = putStrLn name *> pure name
>>> runPhasesForwards $ (,,) <$> now (say "Huey") <*> now (say "Dewey") <*> now (say "Louie")
Huey
Dewey
Louie
("Huey","Dewey","Louie")

Or later to schedule it for the next phase of execution:

>>> runPhasesForwards $ (,,) <$> later (say "Huey") <*> now (say "Dewey") <*> now (say "Louie")
Dewey
Louie
Huey
("Huey","Dewey","Louie")

And delay to delay a set of phased actions by one phase:

>>> runPhasesForwards $ delay ((,,) <$> later (say "Huey") <*> now (say "Dewey")) <*> now (say "Louie")
Louie
Dewey
Huey
("Huey","Dewey","Louie")

Phases can also be run in reverse, but all actions in the same phase still occur in the same order:

>>> runPhasesBackwards $ (,,) <$> later (say "Huey") <*> now (say "Dewey") <*> now (say "Louie")
Huey
Dewey
Louie
("Huey","Dewey","Louie")

Constructors

Lift :: f a -> Phases f a 
(:<*>) :: f (a -> b) -> Phases f a -> Phases f b 

Instances

Instances details
Applicative f => Applicative (Phases f) Source # 
Instance details

Defined in Control.Applicative.Phases

Methods

pure :: a -> Phases f a #

(<*>) :: Phases f (a -> b) -> Phases f a -> Phases f b #

liftA2 :: (a -> b -> c) -> Phases f a -> Phases f b -> Phases f c #

(*>) :: Phases f a -> Phases f b -> Phases f b #

(<*) :: Phases f a -> Phases f b -> Phases f a #

Functor f => Functor (Phases f) Source # 
Instance details

Defined in Control.Applicative.Phases

Methods

fmap :: (a -> b) -> Phases f a -> Phases f b #

(<$) :: a -> Phases f b -> Phases f a #

runPhasesForwards :: Applicative f => Phases f a -> f a Source #

run the phased actions in forwards order

>>> runPhasesForwards $ now (putStrLn "hello") *> later (putStrLn "world")
hello
world
>>> runPhasesForwards $ later (putStrLn "hello") *> now (putStrLn "world")
world
hello

runPhasesBackwards :: Applicative f => Phases f a -> f a Source #

run the phased actions in backwards order

>>> runPhasesBackwards $ now (putStrLn "hello") *> later (putStrLn "world")
world
hello
>>> runPhasesBackwards $ later (putStrLn "hello") *> now (putStrLn "world")
hello
world

now :: f a -> Phases f a Source #

schedule an action to run in the current phase

later :: Applicative f => f a -> Phases f a Source #

schedule an action to run in the next phase

delay :: Applicative f => Phases f a -> Phases f a Source #

delay all actions by a phase