SimpleH-1.0.1: 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 Fold s t a b = forall f. (Semigroup (f b), Applicative f) => LensLike f s t a bSource

type Fold' a b = Fold b b a aSource

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

type Getter' a b = Getter b b a aSource

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) -> 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

simple :: Iso' a b -> Iso' a bSource

(.+) :: Fold s t a b -> Fold s t a b -> Fold s t a bSource

Extracting values

(^.) :: a -> Getter b b a a -> bSource

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

(^..) :: a -> Iso a a b b -> bSource

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

(^??) :: a -> ((b -> Const [b] b) -> a -> Const [b] a) -> [b]Source

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

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

(%%~) :: Iso s t a b -> (b -> a) -> t -> sSource

(%%-) :: Iso s t a b -> a -> t -> sSource

at :: Getter b u a v -> 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 c u b v -> (a -> b) -> a -> cSource

(.-) :: (b -> c) -> Iso a a b 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) (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)) (:.: 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) 

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

_Id :: Iso (Id a) (Id b) a bSource

_OrdList :: Iso (OrdList a) (OrdList b) [a] [b]Source

_Const :: Iso (Const a c) (Const b c) a bSource

_Dual :: Iso (Dual a) (Dual b) a bSource

_Endo :: Iso (Endo k a) (Endo k b) (k a a) (k b b)Source

_Flip :: Iso (Flip f b a) (Flip f d c) (f a b) (f c d)Source

_Max :: Iso (Max a) (Max b) a bSource

_Compose :: Iso ((f :.: g) a) ((f' :.: g') b) (f (g a)) (f' (g' b))Source

_Backwards :: Iso (Backwards f a) (Backwards f b) (f a) (f b)Source

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

_mapping :: (Functor f, Functor f') => Iso s t a b -> Iso (f s) (f' t) (f a) (f' b)Source

_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) 

(<.>) :: IsoFunctor2 f => (a :<->: c) -> (b :<->: d) -> f a b :<->: f c dSource

An infix synonym for mapIso2

class IsoFunctor2 f whereSource

Methods

mapIso2 :: (a :<->: c) -> (b :<->: d) -> f a b :<->: f c dSource

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