Safe Haskell | None |
---|
A module providing simple Lens functionality.
Lenses are a Haskell abstraction that allows you to access and modify part of a structure, compensating for and improving upon Haskell's horrendous record syntax and giving Haskell a first-class record system.
This module defines three kinds of Lenses : Lenses that allow you to
access part of a structure; Traversals that allow you to modify part
of a structure; and Isos which may be reversed. Lenses of any kind can
be composed with (.)
, yielding a Lens of the most general kind, so
that composing a Lens with a Traversal or Iso yields a Lens, and a
Traversal with an Iso yields a Traversal.
- type Iso s t a b = forall p f. (Functor f, Bifunctor p) => p s (f t) -> p a (f b)
- type Iso' a b = Iso b b a a
- type :<->: a b = Iso' a b
- type LensLike f s t a b = (s -> f t) -> a -> f b
- type LensLike' f a b = LensLike f b b a a
- type Getter s t a b = LensLike (Const s) s t a b
- type Getter' u v a b = Getter b u a v
- type Lens s t a b = forall f. Functor f => LensLike f s t a b
- type Lens' a b = Lens b b a a
- type Traversal s t a b = forall f. Applicative f => LensLike f s t a b
- type Traversal' a b = Traversal b b a a
- iso :: (a -> s) -> (t -> b) -> Iso s t a b
- from :: Iso s t a b -> Iso b a t s
- lens :: (a -> s) -> (a -> t -> b) -> Lens s t a b
- getter :: (a -> b) -> Getter' u v a b
- prism :: (a -> b :+: s) -> (a -> t -> b) -> Traversal s t a b
- (^.) :: b -> Getter' u v b c -> c
- (^..) :: b -> Iso s b a c -> c
- (^?) :: (Unit f, Monoid (f b)) => a -> Traversal' a b -> f b
- (%~) :: Traversal s t a b -> (s -> t) -> a -> b
- (%-) :: Traversal s t a b -> t -> a -> b
- at :: Getter' u v a b -> a -> b
- at' :: Iso s t a b -> t -> b
- warp :: Traversal s t a b -> (s -> t) -> a -> b
- set :: Traversal s t a b -> t -> a -> b
- (-.) :: Getter' u v b c -> (a -> b) -> a -> c
- (.-) :: (b -> c) -> Iso s a t b -> a -> c
- _1 :: Lens a b (a :*: c) (b :*: c)
- _2 :: Lens a b (c :*: a) (c :*: b)
- _l :: Traversal a b (a :+: c) (b :+: c)
- _r :: Traversal a b (c :+: a) (c :+: b)
- class Compound a b s t | s -> a, b s -> t where
- _list :: [a] :<->: (() :+: (a :*: [a]))
- _head :: Traversal' [a] a
- _tail :: Traversal' [a] [a]
- class Isomorphic b a t s | t -> b, t a -> s where
- adding :: (Num n, Monoid n) => n -> Iso' n n
- _Id :: (Functor f, Bifunctor p) => p (Id a) (f (Id a)) -> p a (f a)
- _OrdList :: (Functor f, Bifunctor p) => p (OrdList a) (f (OrdList a)) -> p [a] (f [a])
- _Const :: (Functor f, Bifunctor p) => p (Const a b) (f (Const a b)) -> p a (f a)
- _Dual :: (Functor f, Bifunctor p) => p (Dual a) (f (Dual a)) -> p a (f a)
- _Endo :: (Functor f, Bifunctor p) => p (Endo k a) (f (Endo k a)) -> p (k a a) (f (k a a))
- _Flip :: (Functor f1, Bifunctor p) => p (Flip f b a) (f1 (Flip f b a)) -> p (f a b) (f1 (f a b))
- _maybe :: (Functor f, Bifunctor p) => p (Maybe Void) (f (Maybe Void)) -> p Bool (f Bool)
- _Max :: (Functor f, Bifunctor p) => p (Max a) (f (Max a)) -> p a (f a)
- _Compose :: (Functor f1, Bifunctor p) => p (Compose f g a) (f1 (Compose f' g' b)) -> p (f (g a)) (f1 (f' (g' b)))
- _Backwards :: (Functor f, Bifunctor p) => p (Backwards f1 a) (f (Backwards f2 a1)) -> p (f1 a) (f (f2 a1))
- warp2 :: Iso s t a b -> (s -> s -> t) -> a -> a -> b
- _mapping :: Functor f => Iso s t a b -> Iso (f s) (f t) (f a) (f b)
- _promapping :: Bifunctor f => Iso s t a b -> Iso (f t x) (f s y) (f b x) (f a y)
- class IsoFunctor f where
- class IsoFunctor2 f where
- _thunk :: Iso a b (IO a) (IO b)
The lens types
type Traversal s t a b = forall f. Applicative f => LensLike f s t a bSource
type Traversal' a b = Traversal b b a aSource
Constructing lenses
prism :: (a -> b :+: s) -> (a -> t -> b) -> Traversal s t a bSource
Create a Traversal
from a maybe getter and setter function.
prism :: (a -> (a:+:b)) -> (a -> b -> a) -> Traversal'
a b
Extracting values
(^?) :: (Unit f, Monoid (f b)) => a -> Traversal' a b -> f bSource
Basic lenses
_head :: Traversal' [a] aSource
_tail :: Traversal' [a] [a]Source
Isomorphisms
class Isomorphic b a t s | t -> b, t a -> s whereSource
Isomorphic Bool Bool (Maybe Void) (Maybe Void) | |
Isomorphic a b (Max a) (Max b) | |
Isomorphic a b (Dual a) (Dual b) | |
Isomorphic a b (Id a) (Id b) | |
Isomorphic a b (Void, a) (Void, b) | |
Isomorphic a b (Const a c) (Const b c) | |
Isomorphic [a] [b] (OrdList a) (OrdList b) | |
Isomorphic (f (g a)) (f' (g' b)) (Compose f g a) (Compose f' g' b) | |
Isomorphic (k a a) (k b b) (Endo k a) (Endo k b) | |
Isomorphic (a -> m b) (a -> m c) (Kleisli m a b) (Kleisli m a c) | |
Isomorphic (f a b) (f c d) (Flip f b a) (Flip f d c) |
_Flip :: (Functor f1, Bifunctor p) => p (Flip f b a) (f1 (Flip f b a)) -> p (f a b) (f1 (f a b))Source
_Compose :: (Functor f1, Bifunctor p) => p (Compose f g a) (f1 (Compose f' g' b)) -> p (f (g a)) (f1 (f' (g' b)))Source
_Backwards :: (Functor f, Bifunctor p) => p (Backwards f1 a) (f (Backwards f2 a1)) -> p (f1 a) (f (f2 a1))Source
_promapping :: Bifunctor f => Iso s t a b -> Iso (f t x) (f s y) (f b x) (f a y)Source
_promapping :: Bifunctor f => Iso' a b -> Iso' (f a c) (f b c)
class IsoFunctor f whereSource
IsoFunctor ((->) a) |
class IsoFunctor2 f whereSource