SimpleH-0.9: A light, clean and powerful Haskell utility library

Safe HaskellNone

SimpleH.Lens

Contents

Description

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.

Synopsis

The lens types

type Iso s t a b = forall p f. (Functor f, Bifunctor p) => p s (f t) -> p a (f b)Source

type Iso' a b = Iso b b a aSource

type :<->: a b = Iso' a bSource

type LensLike f s t a b = (s -> f t) -> a -> f bSource

type LensLike' f a b = LensLike f b b a aSource

type Getter s t a b = LensLike (Const s) s t a bSource

type Getter' u v a b = Getter b u a vSource

type Lens s t a b = forall f. Functor f => LensLike f s t a bSource

type Lens' a b = Lens b b a aSource

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

iso :: (a -> s) -> (t -> b) -> Iso s t a bSource

Create an Iso from two inverse functions.

from :: Iso s t a b -> Iso b a t sSource

Reverse an Iso

 from :: Iso' a b -> Iso' b a

lens :: (a -> s) -> (a -> t -> b) -> Lens s t a bSource

Create a Lens from a getter and setter function.

 lens :: (a -> b) -> (a -> b -> a) -> Lens' a b

getter :: (a -> b) -> Getter' u v 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

Extracting values

(^.) :: b -> Getter' u v b c -> cSource

Retrieve a value from a structure using a Lens (or Iso)

(^..) :: b -> Iso s b a c -> cSource

(^?) :: (Unit f, Monoid (f b)) => a -> Traversal' a b -> f bSource

(%~) :: Traversal s t a b -> (s -> t) -> a -> bSource

(%-) :: Traversal s t a b -> t -> a -> bSource

at :: Getter' u v a b -> a -> bSource

at' :: Iso s t a b -> t -> bSource

warp :: Traversal s t a b -> (s -> t) -> a -> bSource

set :: Traversal s t a b -> t -> a -> bSource

(-.) :: Getter' u v b c -> (a -> b) -> a -> cSource

(.-) :: (b -> c) -> Iso s a t b -> a -> cSource

Basic lenses

_1 :: Lens a b (a :*: c) (b :*: c)Source

_2 :: Lens a b (c :*: a) (c :*: b)Source

_l :: Traversal a b (a :+: c) (b :+: c)Source

_r :: Traversal a b (c :+: a) (c :+: b)Source

class Compound a b s t | s -> a, b s -> t whereSource

Methods

_each :: Traversal a b s tSource

Instances

Compound a b [a] [b] 
Compound a b (a, a) (b, b) 
Compound a b (a, a, a) (b, b, b) 

_list :: [a] :<->: (() :+: (a :*: [a]))Source

Isomorphisms

class Isomorphic b a t s | t -> b, t a -> s whereSource

Methods

_iso :: Iso s t a bSource

Instances

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) 

adding :: (Num n, Monoid n) => n -> Iso' n nSource

_Id :: (Functor f, Bifunctor p) => p (Id a) (f (Id a)) -> p a (f a)Source

_OrdList :: (Functor f, Bifunctor p) => p (OrdList a) (f (OrdList a)) -> p [a] (f [a])Source

_Const :: (Functor f, Bifunctor p) => p (Const a b) (f (Const a b)) -> p a (f a)Source

_Dual :: (Functor f, Bifunctor p) => p (Dual a) (f (Dual a)) -> p a (f a)Source

_Endo :: (Functor f, Bifunctor p) => p (Endo k a) (f (Endo k a)) -> p (k a a) (f (k a a))Source

_Flip :: (Functor f1, Bifunctor p) => p (Flip f b a) (f1 (Flip f b a)) -> p (f a b) (f1 (f a b))Source

_maybe :: (Functor f, Bifunctor p) => p (Maybe Void) (f (Maybe Void)) -> p Bool (f Bool)Source

_Max :: (Functor f, Bifunctor p) => p (Max a) (f (Max a)) -> p a (f a)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

warp2 :: Iso s t a b -> (s -> s -> t) -> a -> a -> bSource

_mapping :: Functor f => Iso s t a b -> Iso (f s) (f t) (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

Methods

mapIso :: Iso s t a b -> Iso (f s) (f t) (f a) (f b)Source

Instances

IsoFunctor ((->) a) 

class IsoFunctor2 f whereSource

Methods

mapIso2 :: Iso' a b -> Iso' c d -> Iso' (f a c) (f b d)Source

_thunk :: Iso a b (IO a) (IO b)Source