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 Fold s t a b = forall f. (Semigroup (f b), Applicative f) => LensLike f s t a b
- type Fold' a b = Fold b b a a
- type Getter s t a b = LensLike (Const s) s t a b
- type Getter' a b = Getter b b a a
- 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) -> Traversal' a b
- prism :: (a -> b :+: s) -> (a -> t -> b) -> Traversal s t a b
- sat :: (a -> Bool) -> Traversal' a a
- simple :: Iso' a b -> Iso' a b
- (.+) :: Fold s t a b -> Fold s t a b -> Fold s t a b
- (^.) :: 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
- (^??) :: a -> ((b -> Const [b] b) -> a -> Const [b] a) -> [b]
- (%~) :: Traversal s t a b -> (s -> t) -> a -> b
- (%-) :: Traversal s t a b -> t -> a -> b
- (%%~) :: Iso s t a b -> (b -> a) -> t -> s
- (%%-) :: Iso s t a b -> a -> t -> s
- at :: Getter b u a v -> 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 c u b v -> (a -> b) -> a -> c
- (.-) :: (b -> c) -> Iso a a b 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)
- _Just :: Traversal a b (Maybe a) (Maybe 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, Semigroup n) => n -> Iso' n n
- _Id :: Iso (Id a) (Id b) a b
- _OrdList :: Iso (OrdList a) (OrdList b) [a] [b]
- _Const :: Iso (Const a c) (Const b c) a b
- _Dual :: Iso (Dual a) (Dual b) a b
- _Endo :: Iso (Endo k a) (Endo k b) (k a a) (k b b)
- _Flip :: Iso (Flip f b a) (Flip f d c) (f a b) (f c d)
- _maybe :: Iso' Bool (Maybe Void)
- _Max :: Iso (Max a) (Max b) a b
- _Compose :: Iso ((f :.: g) a) ((f' :.: g') b) (f (g a)) (f' (g' b))
- _Backwards :: Iso (Backwards f a) (Backwards f b) (f a) (f b)
- 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)
- class IsoFunctor f where
- (<.>) :: IsoFunctor2 f => (a :<->: c) -> (b :<->: d) -> f a b :<->: f c d
- class IsoFunctor2 f where
- _thunk :: Iso a b (IO a) (IO b)
The lens types
type Fold s t a b = forall f. (Semigroup (f b), Applicative f) => LensLike f s t a bSource
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
getter :: (a -> b) -> Traversal' a bSource
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
sat :: (a -> Bool) -> Traversal' a aSource
Extracting values
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)) (:.: 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) |
_Backwards :: Iso (Backwards f a) (Backwards f b) (f a) (f b)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) |
(<.>) :: IsoFunctor2 f => (a :<->: c) -> (b :<->: d) -> f a b :<->: f c dSource
An infix synonym for mapIso2
class IsoFunctor2 f whereSource