views-1.0: Views allow you to run a State monad on part of a state.

Safe HaskellSafe-Inferred





data View a v Source

The type definition of a view from a to v.

Views allow you to operate on part (the view) of a data structure (the whole) while abstracting the rest.

Note that while views are mostly used for operating on record fields, there are very interesting abstractions that may be conceived from them having nothing whatsoever to do with fields (for example, a view for the bounds of an array, that allows for easy redimensioning, or a view for the associated value to a given key in a map)




extract :: a -> v

Function to extract the view from the whole

inject :: v -> a -> a

Function to reinject the view into the whole


Usual Views

fst_ :: View (v, b) vSource

A view for the first element of a pair

snd_ :: View (a, v) vSource

A view for the second element of a pair

head_ :: View [v] vSource

A view for the head of a list

tail_ :: View [a] [a]Source

A view for the tail of a list

id_ :: View a aSource

The identity view

f_ :: (a -> v) -> View a vSource

A view that encapsulates a function.

Note: A View created with f_ is not a full View, as it doesn't allow reinjection of the view into the whole. This function is thus to be used only for convenience when chaining Views and pure functions.

View-related functions

on :: (t1 -> t1) -> View t t1 -> t -> tSource

f on v expands f to act on the whole of v.

(>>>) :: Category cat => cat a b -> cat b c -> cat a c

Left-to-right composition

(<<<) :: Category cat => cat b c -> cat a b -> cat a c

Right-to-left composition