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 four kinds of Lenses : Folds that allow multiple
readwrites into a structure; Traversals that allow parallel readwrites;
Lenses that allow just a single read/write; and Isos which allow a read and
a write in both directions. Lenses of any kind can be composed with
(.)
, yielding a Lens of the most general kind, so that composing a
Lens with an Iso yields a Lens, and a Traversal with an Iso or a Lens
yields a Traversal.
- type LensLike f s t a b = (s -> f t) -> a -> f b
- type FixFold s t a b = forall m. MonadFix m => LensLike m s t a b
- type FixFold' a b = Simple FixFold a b
- type Fold s t a b = forall m. Monad m => LensLike m s t a b
- type Fold' a b = Simple Fold 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
- 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 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
- 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) -> Lens' 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
- (.+) :: Monad m => LensLike m s t a b -> LensLike m s t b c -> LensLike m s t a c
- 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 ()
- traversel :: LensLike f a b c d -> (a -> f b) -> c -> f d
- traversel_ :: Functor f => LensLike f a a c c -> (a -> f ()) -> c -> f ()
- (^.) :: a -> Lens b b a a -> b
- ($^) :: Lens b b a a -> a -> b
- (^..) :: a -> Iso a a b b -> b
- (^?) :: (Unit f, Monoid (f b), MonadFix ((,) (f b))) => a -> FixFold' a b -> f b
- has :: MonadFix ((,) Bool) => FixFold' a b -> a -> Bool
- (^??) :: MonadFix ((,) [b]) => a -> FixFold' a b -> [b]
- (%~) :: FixFold s t a b -> (s -> t) -> a -> b
- (%-) :: FixFold 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 :: Lens b u a v -> a -> b
- yb :: Iso s t a b -> t -> b
- warp :: FixFold s t a b -> (s -> t) -> a -> b
- set :: FixFold s t a b -> t -> a -> b
- (-.) :: Lens c u b v -> (a -> b) -> a -> c
- (.-) :: (b -> c) -> Iso a a b b -> a -> c
- interpret :: Iso' (r -> a) b -> r -> b -> a
- 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 Lens6 s t a b | a -> s, a t -> b where
- class Lens7 s t a b | a -> s, a t -> b where
- class Lens8 s t a b | a -> s, a t -> b where
- class Lens9 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 Trav3 s t a b | a -> s, a t -> b where
- class Trav4 s t a b | a -> s, a t -> b where
- class Trav5 s t a b | a -> s, a t -> b where
- class Trav6 s t a b | a -> s, a t -> b where
- class Trav7 s t a b | a -> s, a t -> b where
- class Trav8 s t a b | a -> s, a t -> b where
- class Trav9 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]
- t'Just :: Traversal a b (Maybe a) (Maybe b)
- l'Just :: a -> Lens a a (Maybe a) (Maybe 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 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
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 #
traversel_ :: Functor f => LensLike f a a c c -> (a -> f ()) -> c -> f () Source #
Extracting values
Basic lenses
class Lens1 s t a b | a -> s, a t -> b where Source #
Lens1 a a [a] [a] Source # | |
Lens1 x y (Tuple2 x a) (Tuple2 y a) Source # | |
Lens1 a b (Assoc a c) (Assoc b c) Source # | |
Lens1 a a (Cofree f a) (Cofree f a) Source # | |
Lens1 x y (Tuple3 x a b) (Tuple3 y a b) Source # | |
Lens1 x y (Tuple4 x a b c) (Tuple4 y a b c) Source # | |
Lens1 x y (Tuple5 x a b c d) (Tuple5 y a b c d) Source # | |
Lens1 x y (Tuple6 x a b c d e) (Tuple6 y a b c d e) Source # | |
Lens1 x y (Tuple7 x a b c d e f) (Tuple7 y a b c d e f) Source # | |
Lens1 x y (Tuple8 x a b c d e f g) (Tuple8 y a b c d e f g) Source # | |
Lens1 x y (Tuple9 x a b c d e f g h) (Tuple9 y a b c d e f g h) Source # | |
class Lens2 s t a b | a -> s, a t -> b where Source #
Lens2 x y (Tuple2 a x) (Tuple2 a y) Source # | |
Lens2 a b (Assoc c a) (Assoc c b) Source # | |
Lens2 x y (Tuple3 a x b) (Tuple3 a y b) Source # | |
Lens2 x y (Tuple4 a x b c) (Tuple4 a y b c) Source # | |
Lens2 x y (Tuple5 a x b c d) (Tuple5 a y b c d) Source # | |
Lens2 x y (Tuple6 a x b c d e) (Tuple6 a y b c d e) Source # | |
Lens2 x y (Tuple7 a x b c d e f) (Tuple7 a y b c d e f) Source # | |
Lens2 x y (Tuple8 a x b c d e f g) (Tuple8 a y b c d e f g) Source # | |
Lens2 x y (Tuple9 a x b c d e f g h) (Tuple9 a y b c d e f g h) Source # | |
Lens2 (f (Cofree f a)) (f (Cofree f a)) (Cofree f a) (Cofree f a) Source # | |
class Lens3 s t a b | a -> s, a t -> b where Source #
Lens3 x y (Tuple3 a b x) (Tuple3 a b y) Source # | |
Lens3 x y (Tuple4 a b x c) (Tuple4 a b y c) Source # | |
Lens3 x y (Tuple5 a b x c d) (Tuple5 a b y c d) Source # | |
Lens3 x y (Tuple6 a b x c d e) (Tuple6 a b y c d e) Source # | |
Lens3 x y (Tuple7 a b x c d e f) (Tuple7 a b y c d e f) Source # | |
Lens3 x y (Tuple8 a b x c d e f g) (Tuple8 a b y c d e f g) Source # | |
Lens3 x y (Tuple9 a b x c d e f g h) (Tuple9 a b y c d e f g h) Source # | |
class Lens4 s t a b | a -> s, a t -> b where Source #
Lens4 x y (Tuple4 a b c x) (Tuple4 a b c y) Source # | |
Lens4 x y (Tuple5 a b c x d) (Tuple5 a b c y d) Source # | |
Lens4 x y (Tuple6 a b c x d e) (Tuple6 a b c y d e) Source # | |
Lens4 x y (Tuple7 a b c x d e f) (Tuple7 a b c y d e f) Source # | |
Lens4 x y (Tuple8 a b c x d e f g) (Tuple8 a b c y d e f g) Source # | |
Lens4 x y (Tuple9 a b c x d e f g h) (Tuple9 a b c y d e f g h) Source # | |
class Lens5 s t a b | a -> s, a t -> b where Source #
Lens5 x y (Tuple5 a b c d x) (Tuple5 a b c d y) Source # | |
Lens5 x y (Tuple6 a b c d x e) (Tuple6 a b c d y e) Source # | |
Lens5 x y (Tuple7 a b c d x e f) (Tuple7 a b c d y e f) Source # | |
Lens5 x y (Tuple8 a b c d x e f g) (Tuple8 a b c d y e f g) Source # | |
Lens5 x y (Tuple9 a b c d x e f g h) (Tuple9 a b c d y e f g h) Source # | |
class Trav1 s t a b | a -> s, a t -> b where Source #
Trav1 a a [a] [a] Source # | |
Trav1 a b ((:+:) a c) ((:+:) b c) Source # | |
Trav1 x y (Union3 x a b) (Union3 y a b) Source # | |
Trav1 x y (Union4 x a b c) (Union4 y a b c) Source # | |
Trav1 x y (Union5 x a b c d) (Union5 y a b c d) Source # | |
Trav1 x y (Union6 x a b c d e) (Union6 y a b c d e) Source # | |
Trav1 x y (Union7 x a b c d e f) (Union7 y a b c d e f) Source # | |
Trav1 x y (Union8 x a b c d e f g) (Union8 y a b c d e f g) Source # | |
Trav1 x y (Union9 x a b c d e f g h) (Union9 y a b c d e f g h) Source # | |
class Trav2 s t a b | a -> s, a t -> b where Source #
Trav2 a b (Maybe a) (Maybe b) Source # | |
Trav2 a b ((:+:) c a) ((:+:) c b) Source # | |
Trav2 x y (Union3 a x b) (Union3 a y b) Source # | |
Trav2 x y (Union4 a x b c) (Union4 a y b c) Source # | |
Trav2 x y (Union5 a x b c d) (Union5 a y b c d) Source # | |
Trav2 x y (Union6 a x b c d e) (Union6 a y b c d e) Source # | |
Trav2 x y (Union7 a x b c d e f) (Union7 a y b c d e f) Source # | |
Trav2 x y (Union8 a x b c d e f g) (Union8 a y b c d e f g) Source # | |
Trav2 x y (Union9 a x b c d e f g h) (Union9 a y b c d e f g h) Source # | |
class Trav3 s t a b | a -> s, a t -> b where Source #
Trav3 x y (Union3 a b x) (Union3 a b y) Source # | |
Trav3 x y (Union4 a b x c) (Union4 a b y c) Source # | |
Trav3 x y (Union5 a b x c d) (Union5 a b y c d) Source # | |
Trav3 x y (Union6 a b x c d e) (Union6 a b y c d e) Source # | |
Trav3 x y (Union7 a b x c d e f) (Union7 a b y c d e f) Source # | |
Trav3 x y (Union8 a b x c d e f g) (Union8 a b y c d e f g) Source # | |
Trav3 x y (Union9 a b x c d e f g h) (Union9 a b y c d e f g h) Source # | |
class Trav4 s t a b | a -> s, a t -> b where Source #
Trav4 x y (Union4 a b c x) (Union4 a b c y) Source # | |
Trav4 x y (Union5 a b c x d) (Union5 a b c y d) Source # | |
Trav4 x y (Union6 a b c x d e) (Union6 a b c y d e) Source # | |
Trav4 x y (Union7 a b c x d e f) (Union7 a b c y d e f) Source # | |
Trav4 x y (Union8 a b c x d e f g) (Union8 a b c y d e f g) Source # | |
Trav4 x y (Union9 a b c x d e f g h) (Union9 a b c y d e f g h) Source # | |
class Trav5 s t a b | a -> s, a t -> b where Source #
Trav5 x y (Union5 a b c d x) (Union5 a b c d y) Source # | |
Trav5 x y (Union6 a b c d x e) (Union6 a b c d y e) Source # | |
Trav5 x y (Union7 a b c d x e f) (Union7 a b c d y e f) Source # | |
Trav5 x y (Union8 a b c d x e f g) (Union8 a b c d y e f g) Source # | |
Trav5 x y (Union9 a b c d x e f g h) (Union9 a b c d y e f g h) Source # | |
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) Source # | |
Isomorphic a b (Max a) (Max b) Source # | |
Isomorphic a b (Product a) (Product b) Source # | |
Isomorphic a b (Dual a) (Dual b) Source # | |
Isomorphic a b (Id a) (Id b) Source # | |
Isomorphic a b (Void, a) (Void, b) Source # | |
Isomorphic a b (Const a c) (Const b c) Source # | |
Isomorphic [a] [b] (OrdList a) (OrdList b) Source # | |
Isomorphic (f (g a)) (f' (g' b)) ((:.:) f g a) ((:.:) f' g' b) Source # | |
Isomorphic (k a a) (k b b) (Endo k a) (Endo k b) Source # | |
Isomorphic (a -> m b) (c -> m' d) (Kleisli m a b) (Kleisli m' c d) Source # | |
Isomorphic (f a b) (f c d) (Flip f b a) (Flip f d c) Source # | |
Miscellaneous
Type wrappers
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)
class IsoFunctor f where Source #
IsoFunctor ((->) a) Source # | |