digestive-functors-0.1.0.1: A general way to consume input using applicative functors

Text.Digestive.Types

Description

Core types

Synopsis

Documentation

newtype View e v Source

A view represents a visual representation of a form. It is composed of a function which takes a list of all errors and then produces a new view

Constructors

View 

Fields

unView :: [(FormRange, e)] -> v
 

Instances

Functor (View e) 
Monoid v => Monoid (View e v) 

data Environment m i Source

The environment is where you get the actual input per form. The environment itself is optional

Constructors

Environment (FormId -> m (Maybe i)) 
NoEnvironment 

Instances

Monad m => Monoid (Environment m i) 

fromList :: Monad m => [(FormId, i)] -> Environment m iSource

Create an environment from a lookup table

type FormState m i a = ReaderT (Environment m i) (StateT FormRange m) aSource

The form state is a state monad under which our applicatives are composed

getFormId :: Monad m => FormState m i FormIdSource

Utility function: returns the current FormId. This will only make sense if the form is not composed

getFormRange :: Monad m => FormState m i FormRangeSource

Utility function: Get the current range

getFormInput :: Monad m => FormState m i (Maybe i)Source

Utility function: Get the current input

getFormInput' :: Monad m => FormId -> FormState m i (Maybe i)Source

Gets the input of an arbitrary FormId.

isFormInput :: Monad m => FormState m i BoolSource

Check if any form input is present

newtype Form m i e v a Source

A form represents a number of composed fields

Constructors

Form 

Fields

unForm :: FormState m i (View e v, Result e a)
 

Instances

Monad m => Functor (Form m i e v) 
(Monad m, Monoid v) => Applicative (Form m i e v) 

type Formlet m i e v a = Maybe a -> Form m i e v aSource

A function for generating forms with an optional default value.

viewSource

Arguments

:: Monad m 
=> v

View to insert

-> Form m i e v ()

Resulting form

Insert a view into the functor

(++>) :: (Monad m, Monoid v) => Form m i e v () -> Form m i e v a -> Form m i e v aSource

Append a unit form to the left. This is useful for adding labels or error fields

(<++) :: (Monad m, Monoid v) => Form m i e v a -> Form m i e v () -> Form m i e v aSource

Append a unit form to the right. See ++>.

mapViewSource

Arguments

:: (Monad m, Functor m) 
=> (v -> w)

Manipulator

-> Form m i e v a

Initial form

-> Form m i e w a

Resulting form

Change the view of a form using a simple function

runFormSource

Arguments

:: Monad m 
=> Form m i e v a

Form to run

-> String

Identifier for the form

-> Environment m i

Input environment

-> m (View e v, Result e a)

Result

Run a form

eitherFormSource

Arguments

:: Monad m 
=> Form m i e v a

Form to run

-> String

Identifier for the form

-> Environment m i

Input environment

-> m (Either v a)

Result

Evaluate a form to it's view if it fails

viewFormSource

Arguments

:: Monad m 
=> Form m i e v a

Form to run

-> String

Identifier for the form

-> m v

Result

Just evaluate the form to a view. This usually maps to a GET request in the browser.