Safe Haskell | None |
---|---|
Language | Haskell2010 |
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 = Simple Iso a b
- type (:<->:) a b = Iso' a b
- type LensLike f s t a b = (s -> f t) -> a -> f b
- type Fold s t a b = forall f. (Semigroup (f b), Applicative f) => LensLike f s t a b
- type Fold' a b = Simple Fold a b
- type Getter s t a b = LensLike (Const s) s t a b
- type Getter' a b = Simple Getter a b
- type Lens s t a b = forall f. Functor f => LensLike f s t a b
- type Lens' a b = Simple Lens a b
- type Traversal s t a b = forall f. Applicative f => LensLike f s t a b
- type Traversal' a b = Simple Traversal a b
- 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) -> Traversal' a b
- prism :: (a -> b :+: s) -> (a -> t -> b) -> Traversal s t a b
- sat :: (a -> Bool) -> Traversal' a a
- simple :: LensLike f a b a b -> LensLike f a b a b
- (.+) :: Fold s t a b -> Fold s t a b -> Fold s t a b
- forl :: LensLike f a b c d -> c -> (a -> f b) -> f d
- forl_ :: Functor f => LensLike f a a c c -> c -> (a -> f ()) -> f ()
- (^.) :: a -> Getter b b a a -> b
- (^..) :: a -> Iso a a b b -> b
- (^?) :: (Unit f, Monoid (f b)) => a -> Fold' a b -> f b
- has :: Fold' a b -> a -> Bool
- (^??) :: a -> ((b -> Const [b] b) -> a -> Const [b] a) -> [b]
- (%~) :: LensLike Id s t a b -> (s -> t) -> a -> b
- (%-) :: LensLike Id s t a b -> t -> a -> b
- (%%~) :: Iso s t a b -> (b -> a) -> t -> s
- (%%-) :: Iso s t a b -> a -> t -> s
- by :: Getter b u a v -> a -> b
- yb :: Iso s t a b -> t -> b
- warp :: LensLike Id s t a b -> (s -> t) -> a -> b
- set :: LensLike Id s t a b -> t -> a -> b
- (-.) :: Getter c u b v -> (a -> b) -> a -> c
- (.-) :: (b -> c) -> Iso a a b b -> a -> c
- class Lens1 s t a b | a -> s, a t -> b where
- class Lens2 s t a b | a -> s, a t -> b where
- class Lens3 s t a b | a -> s, a t -> b where
- class Lens4 s t a b | a -> s, a t -> b where
- class Lens5 s t a b | a -> s, a t -> b where
- class Trav1 s t a b | a -> s, a t -> b where
- class Trav2 s t a b | a -> s, a t -> b where
- class Compound a b s t | s -> a, b s -> t where
- i'list :: [a] :<->: (() :+: (a :*: [a]))
- i'pair :: Iso s t a b -> Iso s' t' a' b' -> Iso (s, s') (t, t') (a, a') (b, b')
- t'head :: Traversal' [a] a
- t'tail :: Traversal' [a] [a]
- class Isomorphic b a t s | t -> b, t a -> s where
- thunk :: Iso a b (IO a) (IO b)
- chunk :: Bytes :<->: Chunk
- curried :: Iso (a -> b -> c) (a' -> b' -> c') ((a, b) -> c) ((a', b') -> c')
- i'Id :: Iso (Id a) (Id b) a b
- i'OrdList :: Iso (OrdList a) (OrdList b) [a] [b]
- i'Const :: Iso (Const a c) (Const b c) a b
- i'Dual :: Iso (Dual a) (Dual b) a b
- i'Endo :: Iso (Endo k a) (Endo k b) (k a a) (k b b)
- i'Flip :: Iso (Flip f b a) (Flip f d c) (f a b) (f c d)
- i'maybe :: Iso (Maybe Void) (Maybe a) Bool Bool
- i'Max :: Iso (Max a) (Max b) a b
- i'Compose :: Iso ((f :.: g) a) ((f' :.: g') b) (f (g a)) (f' (g' b))
- i'Backwards :: Iso (Backwards f a) (Backwards g b) (f a) (g b)
- i'Accum :: Iso (Accum a) (Accum b) (Maybe a) (Maybe b)
- negated :: (Disjonctive a, Disjonctive b) => Iso a b a b
- commuted :: Commutative f => Iso (f a b) (f c d) (f b a) (f d c)
- adding :: (Num n, Semigroup n) => n -> Iso' n n
- warp2 :: Iso s t a b -> (s -> s -> t) -> a -> a -> b
- mapping :: (Functor f, Functor f') => Iso s t a b -> Iso (f s) (f' t) (f a) (f' 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)
- applying :: Applicative f => Lens s t a b -> Lens (f s) (f t) (f a) (f b)
- class IsoFunctor f where
- (<.>) :: IsoFunctor2 f => (a :<->: c) -> (b :<->: d) -> f a b :<->: f c d
- class IsoFunctor2 f where
The lens types
type Fold s t a b = forall f. (Semigroup (f b), Applicative f) => LensLike f s t a b Source
type Traversal s t a b = forall f. Applicative f => LensLike f s t a b Source
type Traversal' a b = Simple Traversal a b Source
Constructing lenses
getter :: (a -> b) -> Traversal' a b Source
prism :: (a -> b :+: s) -> (a -> t -> b) -> Traversal s t a b Source
Create a Traversal
from a maybe getter and setter function.
prism :: (a -> (a:+:b)) -> (a -> b -> a) -> Traversal'
a b
sat :: (a -> Bool) -> Traversal' a a Source
Extracting values
Basic lenses
t'head :: Traversal' [a] a Source
t'tail :: Traversal' [a] [a] Source
Isomorphisms
class Isomorphic b a t s | t -> b, t a -> s where Source
Isomorphic Bool Bool (Maybe a) (Maybe Void) | |
Isomorphic a b (Max a) (Max b) | |
Isomorphic a b (Product a) (Product 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)) ((:.:) f g a) ((:.:) f' g' b) | |
Isomorphic (k a a) (k b b) (Endo k a) (Endo k b) | |
Isomorphic (a -> m b) (c -> m' d) (Kleisli m a b) (Kleisli m' c d) | |
Isomorphic (f a b) (f c d) (Flip f b a) (Flip f d c) |
Miscellaneous
Type wrappers
i'Backwards :: Iso (Backwards f a) (Backwards g b) (f a) (g b) Source
Algebraic isomorphisms
negated :: (Disjonctive a, Disjonctive b) => Iso a b a b Source
commuted :: Commutative f => Iso (f a b) (f c d) (f b a) (f d c) Source
Higher-order isomorphisms
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)
applying :: Applicative f => Lens s t a b -> Lens (f s) (f t) (f a) (f b) Source
class IsoFunctor f where Source
IsoFunctor ((->) a) |
(<.>) :: IsoFunctor2 f => (a :<->: c) -> (b :<->: d) -> f a b :<->: f c d infixr 9 Source
An infix synonym for mapIso2
class IsoFunctor2 f where Source