Module

Data.Lens

Package
profunctor-lenses
Repository
purerl/purescript-profunctor-lenses

This module re-exports types and functions from other modules:

  • module Data.Lens.Iso
  • module Data.Lens.Lens
  • module Data.Lens.Prism
  • module Data.Lens.Traversal
  • module Data.Lens.Types
  • module Data.Lens.Setter
  • module Data.Lens.Getter
  • module Data.Lens.Fold
  • module Data.Lens.Common

Re-exports from Data.Lens.Common

#united Source

united :: forall a. Lens' a Unit

There is a Unit in everything.

#second Source

second :: forall p a b c. Strong p => p b c -> p (Tuple a b) (Tuple a c)

#right Source

right :: forall p a b c. Choice p => p b c -> p (Either a b) (Either a c)

#left Source

left :: forall p a b c. Choice p => p a b -> p (Either a c) (Either b c)

#first Source

first :: forall p a b c. Strong p => p a b -> p (Tuple a c) (Tuple b c)

#_Right Source

_Right :: forall a b c. Prism (Either c a) (Either c b) a b

Prism for the Right constructor of Either.

#_Nothing Source

_Nothing :: forall a b. Prism (Maybe a) (Maybe b) Unit Unit

Prism for the Nothing constructor of Maybe.

#_Left Source

_Left :: forall a b c. Prism (Either a c) (Either b c) a b

Prism for the Left constructor of Either.

#_Just Source

_Just :: forall a b. Prism (Maybe a) (Maybe b) a b

Prism for the Just constructor of Maybe.

#_2 Source

_2 :: forall a b c. Lens (Tuple c a) (Tuple c b) a b

Lens for the second component of a Tuple.

#_1 Source

_1 :: forall a b c. Lens (Tuple a c) (Tuple b c) a b

Lens for the first component of a Tuple.

Re-exports from Data.Lens.Fold

#unfolded Source

unfolded :: forall r s t a b. Monoid r => (s -> Maybe (Tuple a s)) -> Fold r s t a b

Builds a Fold using an unfold.

#toListOfOn Source

toListOfOn :: forall s t a b. s -> Fold (Endo Function (List a)) s t a b -> List a

Synonym for toListOf, reversed.

#toListOf Source

toListOf :: forall s t a b. Fold (Endo Function (List a)) s t a b -> s -> List a

Collects the foci of a Fold into a list.

#toArrayOfOn Source

toArrayOfOn :: forall s t a b. s -> Fold (Endo Function (List a)) s t a b -> Array a

Synonym for toArrayOf, reversed.

#toArrayOf Source

toArrayOf :: forall s t a b. Fold (Endo Function (List a)) s t a b -> s -> Array a

Collects the foci of a Fold into an array.

#sumOf Source

sumOf :: forall s t a b. Semiring a => Fold (Additive a) s t a b -> s -> a

The sum of all foci of a Fold.

#sequenceOf_ Source

sequenceOf_ :: forall f s t a b. Applicative f => Fold (Endo Function (f Unit)) s t (f a) b -> s -> f Unit

Sequence the foci of a Fold, pulling out an Applicative, and ignore the result. If you need the result, see sequenceOf for Traversals.

#replicated Source

replicated :: forall a b t r. Monoid r => Int -> Fold r a b a t

Replicates the elements of a fold.

#productOf Source

productOf :: forall s t a b. Semiring a => Fold (Multiplicative a) s t a b -> s -> a

The product of all foci of a Fold.

#previewOn Source

previewOn :: forall s t a b. s -> Fold (First a) s t a b -> Maybe a

Synonym for preview, flipped.

#preview Source

preview :: forall s t a b. Fold (First a) s t a b -> s -> Maybe a

Previews the first value of a fold, if there is any.

#orOf Source

orOf :: forall s t a b. HeytingAlgebra a => Fold (Disj a) s t a b -> s -> a

The disjunction of all foci of a Fold.

#notElemOf Source

notElemOf :: forall s t a b. Eq a => Fold (Conj Boolean) s t a b -> a -> s -> Boolean

Whether a Fold not contains a given element.

#minimumOf Source

minimumOf :: forall s t a b. Ord a => Fold (Endo Function (Maybe a)) s t a b -> s -> Maybe a

The minimum of all foci of a Fold, if there is any.

#maximumOf Source

maximumOf :: forall s t a b. Ord a => Fold (Endo Function (Maybe a)) s t a b -> s -> Maybe a

The maximum of all foci of a Fold, if there is any.

#lengthOf Source

lengthOf :: forall s t a b. Fold (Additive Int) s t a b -> s -> Int

The number of foci of a Fold.

#lastOf Source

lastOf :: forall s t a b. Fold (Last a) s t a b -> s -> Maybe a

The last focus of a Fold, if there is any.

#itraverseOf_ Source

itraverseOf_ :: forall i f s t a b r. Applicative f => IndexedFold (Endo Function (f Unit)) i s t a b -> (i -> a -> f r) -> s -> f Unit

Traverse the foci of an IndexedFold, discarding the results.

#itoListOf Source

itoListOf :: forall i s t a b. IndexedFold (Endo Function (List (Tuple i a))) i s t a b -> s -> List (Tuple i a)

Collects the foci of an IndexedFold into a list.

#ifoldrOf Source

ifoldrOf :: forall i s t a b r. IndexedFold (Endo Function r) i s t a b -> (i -> a -> r -> r) -> r -> s -> r

Right fold over an IndexedFold.

#ifoldlOf Source

ifoldlOf :: forall i s t a b r. IndexedFold (Dual (Endo Function r)) i s t a b -> (i -> r -> a -> r) -> r -> s -> r

Left fold over an IndexedFold.

#ifoldMapOf Source

ifoldMapOf :: forall r i s t a b. IndexedFold r i s t a b -> (i -> a -> r) -> s -> r

Fold map over an IndexedFold.

#ianyOf Source

ianyOf :: forall i s t a b r. HeytingAlgebra r => IndexedFold (Disj r) i s t a b -> (i -> a -> r) -> s -> r

Whether any focus of an IndexedFold satisfies a predicate.

#iallOf Source

iallOf :: forall i s t a b r. HeytingAlgebra r => IndexedFold (Conj r) i s t a b -> (i -> a -> r) -> s -> r

Whether all foci of an IndexedFold satisfy a predicate.

#hasn't Source

hasn't :: forall s t a b r. HeytingAlgebra r => Fold (Conj r) s t a b -> s -> r

Determines whether a Fold does not have a focus.

#has Source

has :: forall s t a b r. HeytingAlgebra r => Fold (Disj r) s t a b -> s -> r

Determines whether a Fold has at least one focus.

#foldrOf Source

foldrOf :: forall s t a b r. Fold (Endo Function r) s t a b -> (a -> r -> r) -> r -> s -> r

Right fold over a Fold.

#foldlOf Source

foldlOf :: forall s t a b r. Fold (Dual (Endo Function r)) s t a b -> (r -> a -> r) -> r -> s -> r

Left fold over a Fold.

#folded Source

folded :: forall g a b t r. Monoid r => Foldable g => Fold r (g a) b a t

Folds over a Foldable container.

#foldOf Source

foldOf :: forall s t a b. Fold a s t a b -> s -> a

Folds all foci of a Fold to one. Note that this is the same as view.

#foldMapOf Source

foldMapOf :: forall s t a b r. Fold r s t a b -> (a -> r) -> s -> r

Maps and then folds all foci of a Fold.

#firstOf Source

firstOf :: forall s t a b. Fold (First a) s t a b -> s -> Maybe a

The first focus of a Fold, if there is any. Synonym for preview.

#findOf Source

findOf :: forall s t a b. Fold (Endo Function (Maybe a)) s t a b -> (a -> Boolean) -> s -> Maybe a

Find the first focus of a Fold that satisfies a predicate, if there is any.

#filtered Source

filtered :: forall p a. Choice p => (a -> Boolean) -> Optic' p a a

Filters on a predicate.

#elemOf Source

elemOf :: forall s t a b. Eq a => Fold (Disj Boolean) s t a b -> a -> s -> Boolean

Whether a Fold contains a given element.

#anyOf Source

anyOf :: forall s t a b r. HeytingAlgebra r => Fold (Disj r) s t a b -> (a -> r) -> s -> r

Whether any focus of a Fold satisfies a predicate.

#andOf Source

andOf :: forall s t a b. HeytingAlgebra a => Fold (Conj a) s t a b -> s -> a

The conjunction of all foci of a Fold.

#allOf Source

allOf :: forall s t a b r. HeytingAlgebra r => Fold (Conj r) s t a b -> (a -> r) -> s -> r

Whether all foci of a Fold satisfy a predicate.

#(^?) Source

Operator alias for Data.Lens.Fold.previewOn (left-associative / precedence 8)

#(^..) Source

Operator alias for Data.Lens.Fold.toListOfOn (left-associative / precedence 8)

Re-exports from Data.Lens.Getter

#viewOn Source

viewOn :: forall s t a b. s -> AGetter s t a b -> a

Synonym for view, flipped.

#view Source

view :: forall s t a b. AGetter s t a b -> s -> a

View the focus of a Getter.

#use Source

use :: forall s t a b m. MonadState s m => Getter s t a b -> m a

View the focus of a Getter in the state of a monad.

#to Source

to :: forall s t a b. (s -> a) -> Getter s t a b

Convert a function into a getter.

#takeBoth Source

takeBoth :: forall s t a b c d. AGetter s t a b -> AGetter s t c d -> Getter s t (Tuple a c) (Tuple b d)

Combine two getters.

#iview Source

iview :: forall i s t a b. IndexedFold (Tuple i a) i s t a b -> s -> Tuple i a

View the focus of a Getter and its index.

#iuse Source

iuse :: forall i s t a b m. MonadState s m => IndexedFold (Tuple i a) i s t a b -> m (Tuple i a)

View the focus of a Getter and its index in the state of a monad.

#cloneGetter Source

cloneGetter :: forall s t a b. AGetter s t a b -> Getter s t a b

#(^.) Source

Operator alias for Data.Lens.Getter.viewOn (left-associative / precedence 8)

Re-exports from Data.Lens.Grate

#Grate' Source

type Grate' s a = Grate s s a a

#Grate Source

type Grate s t a b = forall p. Closed p => Optic p s t a b

A grate (http://r6research.livejournal.com/28050.html)

#zipWithOf Source

zipWithOf :: forall s t a b. Optic Zipping s t a b -> (a -> a -> b) -> s -> s -> t

#zipFWithOf Source

zipFWithOf :: forall f s t a b. Optic (Costar f) s t a b -> (f a -> b) -> (f s -> t)

#collectOf Source

collectOf :: forall f s t a b. Functor f => Optic (Costar f) s t a (f a) -> (b -> s) -> f b -> t

Re-exports from Data.Lens.Iso

#withIso Source

withIso :: forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r

Extracts the pair of morphisms from an isomorphism.

#under Source

under :: forall s t a b. AnIso s t a b -> (t -> s) -> b -> a

#uncurried Source

uncurried :: forall a b c d e f. Iso (a -> b -> c) (d -> e -> f) (Tuple a b -> c) (Tuple d e -> f)

#re Source

re :: forall p s t a b. Optic (Re p a b) s t a b -> Optic p b a t s

Reverses an optic.

#non Source

non :: forall a. Eq a => a -> Iso' (Maybe a) a

If a1 is obtained from a by removing a single value, then Maybe a1 is isomorphic to a.

#iso Source

iso :: forall s t a b. (s -> a) -> (b -> t) -> Iso s t a b

Create an Iso from a pair of morphisms.

#flipped Source

flipped :: forall a b c d e f. Iso (a -> b -> c) (d -> e -> f) (b -> a -> c) (e -> d -> f)

#curried Source

curried :: forall a b c d e f. Iso (Tuple a b -> c) (Tuple d e -> f) (a -> b -> c) (d -> e -> f)

#cloneIso Source

cloneIso :: forall s t a b. AnIso s t a b -> Iso s t a b

Extracts an Iso from AnIso.

#auf Source

auf :: forall s t a b e r p. Profunctor p => AnIso s t a b -> (p r a -> e -> b) -> p r s -> e -> t

#au Source

au :: forall s t a b e. AnIso s t a b -> ((b -> t) -> e -> s) -> e -> a

Re-exports from Data.Lens.Lens

#withLens Source

withLens :: forall s t a b r. ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r

#lensStore Source

lensStore :: forall s t a b. ALens s t a b -> s -> Tuple a (b -> t)

Converts a lens into the form that lens' accepts.

Can be useful when defining a lens where the focus appears under multiple constructors of an algebraic data type. This function would be called for each case of the data type.

For example:

data LensStoreExample = LensStoreA Int | LensStoreB (Tuple Boolean Int)

lensStoreExampleInt :: Lens' LensStoreExample Int
lensStoreExampleInt = lens' case _ of
  LensStoreA i -> map LensStoreA <$> lensStore identity i
  LensStoreB i -> map LensStoreB <$> lensStore _2 i

#lens' Source

lens' :: forall s t a b. (s -> Tuple a (b -> t)) -> Lens s t a b

#lens Source

lens :: forall s t a b. (s -> a) -> (s -> b -> t) -> Lens s t a b

Create a Lens from a getter/setter pair.

> species = lens _.species $ _ {species = _}
> view species {species : "bovine"}
"bovine"

> _2 = lens Tuple.snd $ \(Tuple keep _) new -> Tuple keep new

Note: _2 is predefined in Data.Lens.Tuple.

#cloneLens Source

cloneLens :: forall s t a b. ALens s t a b -> Lens s t a b

Re-exports from Data.Lens.Prism

#withPrism Source

withPrism :: forall s t a b r. APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r

#review Source

review :: forall s t a b. Review s t a b -> b -> t

Create the "whole" corresponding to a specific "part":

review solidFocus Color.white == Solid Color.white

#prism' Source

prism' :: forall s a. (a -> s) -> (s -> Maybe a) -> Prism' s a

Create a Prism from a constructor and a matcher function that produces a Maybe:

solidFocus :: Prism' Fill Color
solidFocus = prism' Solid case _ of
  Solid color -> Just color
  _ -> Nothing

#prism Source

prism :: forall s t a b. (b -> t) -> (s -> Either t a) -> Prism s t a b

Create a Prism from a constructor and a matcher function that produces an Either:

solidFocus :: Prism' Fill Color
solidFocus = prism Solid case _ of
  Solid color -> Right color
  anotherCase -> Left anotherCase

Note: The matcher function returns a result wrapped in Either t to allow for type-changing prisms in the case where the input does not match.

#only Source

only :: forall a. Eq a => a -> Prism a a Unit Unit

only focuses not just on a case, but a specific value of that case.

solidWhiteFocus :: Prism' Fill Unit
solidWhiteFocus = only $ Solid Color.white

is      solidWhiteFocus (Solid Color.white) == true
preview solidWhiteFocus (Solid Color.white) == Just unit
review  solidWhiteFocus unit                == Solid Color.white

Note: only depends on Eq. Strange definitions of (==) (for example, that it counts any Fill as being equal to Solid Color.white) will create a prism that violates the preview-review law.

#nearly Source

nearly :: forall a. a -> (a -> Boolean) -> Prism' a Unit

nearly is a variant of only. Like only, nearly produces a prism that matches a single value. Unlike only, it uses a predicate you supply instead of depending on class Eq:

solidWhiteFocus :: Prism' Fill Unit
solidWhiteFocus = nearly (Solid Color.white) predicate
  where
    predicate candidate =
      color.toHexString == Color.white.toHexString

#matching Source

matching :: forall s t a b. APrism s t a b -> s -> Either t a

#isn't Source

isn't :: forall s t a b r. HeytingAlgebra r => APrism s t a b -> s -> r

Ask if preview prism would produce a Nothing.

#is Source

is :: forall s t a b r. HeytingAlgebra r => APrism s t a b -> s -> r

Ask if preview prism would produce a Just.

#clonePrism Source

clonePrism :: forall s t a b. APrism s t a b -> Prism s t a b

Re-exports from Data.Lens.Setter

#subOver Source

subOver :: forall s t a. Ring a => Setter s t a a -> a -> s -> t

#subModifying Source

subModifying :: forall s a m. MonadState s m => Ring a => Setter' s a -> a -> m Unit

#setJust Source

setJust :: forall s t a b. Setter s t a (Maybe b) -> b -> s -> t

#set Source

set :: forall s t a b. Setter s t a b -> b -> s -> t

Set the foci of a Setter to a constant value.

#over Source

over :: forall s t a b. Setter s t a b -> (a -> b) -> s -> t

Apply a function to the foci of a Setter.

#mulOver Source

mulOver :: forall s t a. Semiring a => Setter s t a a -> a -> s -> t

#mulModifying Source

mulModifying :: forall s a m. MonadState s m => Semiring a => Setter' s a -> a -> m Unit

#modifying Source

modifying :: forall s a b m. MonadState s m => Setter s s a b -> (a -> b) -> m Unit

Modify the foci of a Setter in a monadic state.

#iover Source

iover :: forall i s t a b. IndexedSetter i s t a b -> (i -> a -> b) -> s -> t

Apply a function to the foci of a Setter that may vary with the index.

#divOver Source

divOver :: forall s t a. EuclideanRing a => Setter s t a a -> a -> s -> t

#divModifying Source

divModifying :: forall s a m. MonadState s m => EuclideanRing a => Setter' s a -> a -> m Unit

#disjOver Source

disjOver :: forall s t a. HeytingAlgebra a => Setter s t a a -> a -> s -> t

#disjModifying Source

disjModifying :: forall s a m. MonadState s m => HeytingAlgebra a => Setter' s a -> a -> m Unit

#conjOver Source

conjOver :: forall s t a. HeytingAlgebra a => Setter s t a a -> a -> s -> t

#conjModifying Source

conjModifying :: forall s a m. MonadState s m => HeytingAlgebra a => Setter' s a -> a -> m Unit

#assignJust Source

assignJust :: forall s a b m. MonadState s m => Setter s s a (Maybe b) -> b -> m Unit

#assign Source

assign :: forall s a b m. MonadState s m => Setter s s a b -> b -> m Unit

Set the foci of a Setter in a monadic state to a constant value.

#appendOver Source

appendOver :: forall s t a. Semigroup a => Setter s t a a -> a -> s -> t

#appendModifying Source

appendModifying :: forall s a m. MonadState s m => Semigroup a => Setter' s a -> a -> m Unit

#addOver Source

addOver :: forall s t a. Semiring a => Setter s t a a -> a -> s -> t

#addModifying Source

addModifying :: forall s a m. MonadState s m => Semiring a => Setter' s a -> a -> m Unit

#(||~) Source

Operator alias for Data.Lens.Setter.disjOver (right-associative / precedence 4)

#(||=) Source

Operator alias for Data.Lens.Setter.disjModifying (non-associative / precedence 4)

#(?~) Source

Operator alias for Data.Lens.Setter.setJust (right-associative / precedence 4)

#(?=) Source

Operator alias for Data.Lens.Setter.assignJust (non-associative / precedence 4)

#(<>~) Source

Operator alias for Data.Lens.Setter.appendOver (right-associative / precedence 4)

#(<>=) Source

Operator alias for Data.Lens.Setter.appendModifying (non-associative / precedence 4)

#(//~) Source

Operator alias for Data.Lens.Setter.divOver (right-associative / precedence 4)

#(//=) Source

Operator alias for Data.Lens.Setter.divModifying (non-associative / precedence 4)

#(.~) Source

Operator alias for Data.Lens.Setter.set (right-associative / precedence 4)

#(.=) Source

Operator alias for Data.Lens.Setter.assign (non-associative / precedence 4)

#(-~) Source

Operator alias for Data.Lens.Setter.subOver (right-associative / precedence 4)

#(-=) Source

Operator alias for Data.Lens.Setter.subModifying (non-associative / precedence 4)

#(+~) Source

Operator alias for Data.Lens.Setter.addOver (right-associative / precedence 4)

#(+=) Source

Operator alias for Data.Lens.Setter.addModifying (non-associative / precedence 4)

#(*~) Source

Operator alias for Data.Lens.Setter.mulOver (right-associative / precedence 4)

#(*=) Source

Operator alias for Data.Lens.Setter.mulModifying (non-associative / precedence 4)

#(&&~) Source

Operator alias for Data.Lens.Setter.conjOver (right-associative / precedence 4)

#(&&=) Source

Operator alias for Data.Lens.Setter.conjModifying (non-associative / precedence 4)

#(%~) Source

Operator alias for Data.Lens.Setter.over (right-associative / precedence 4)

#(%=) Source

Operator alias for Data.Lens.Setter.modifying (non-associative / precedence 4)

Re-exports from Data.Lens.Traversal

#traversed Source

traversed :: forall t a b. Traversable t => Traversal (t a) (t b) a b

A Traversal for the elements of a Traversable functor.

over traversed negate [1, 2, 3] == [-1,-2,-3]
over traversed negate (Just 3) == Just -3

#traverseOf Source

traverseOf :: forall f s t a b. Optic (Star f) s t a b -> (a -> f b) -> s -> f t

Turn a pure profunctor Traversal into a lens-like Traversal.

#sequenceOf Source

sequenceOf :: forall f s t a. Optic (Star f) s t (f a) a -> s -> f t

Sequence the foci of an optic, pulling out an "effect". If you do not need the result, see sequenceOf_ for Folds.

sequenceOf traversed has the same result as Data.Traversable.sequence:

sequenceOf traversed (Just [1, 2]) == [Just 1, Just 2]
sequence             (Just [1, 2]) == [Just 1, Just 2]

An example with effects:

> array = [random, random]
> :t array
Array (Eff ... Number)

> effect = sequenceOf traversed array
> :t effect
Eff ... (Array Number)

> effect >>= logShow
[0.15556037108154985,0.28500369615270515]
unit

#itraverseOf Source

itraverseOf :: forall f i s t a b. IndexedOptic (Star f) i s t a b -> (i -> a -> f b) -> s -> f t

Turn a pure profunctor IndexedTraversal into a lens-like IndexedTraversal.

#failover Source

failover :: forall f s t a b. Alternative f => Optic (Star (Tuple (Disj Boolean))) s t a b -> (a -> b) -> s -> f t

Tries to map over a Traversal; returns empty if the traversal did not have any new focus.

#elementsOf Source

elementsOf :: forall p i s t a. Wander p => IndexedTraversal i s t a a -> (i -> Boolean) -> IndexedOptic p i s t a a

Traverse elements of an IndexedTraversal whose index satisfy a predicate.

#element Source

element :: forall p s t a. Wander p => Int -> Traversal s t a a -> Optic p s t a a

Combine an index and a traversal to narrow the focus to a single element. Compare to Data.Lens.Index.

set     (element 2 traversed) 8888 [0, 0, 3] == [0, 0, 8888]
preview (element 2 traversed)      [0, 0, 3] == Just 3

The resulting traversal is called an affine traversal, which means that the traversal focuses on one or zero (if the index is out of range) results.

Re-exports from Data.Lens.Types

#Traversal' Source

type Traversal' s a = Traversal s s a a

#Traversal Source

type Traversal s t a b = forall p. Wander p => Optic p s t a b

A traversal.

#Tagged Source

newtype Tagged :: forall k. k -> Type -> Typenewtype Tagged a b

Constructors

Instances

#Shop Source

data Shop a b s t

The Shop profunctor characterizes a Lens.

Constructors

  • Shop (s -> a) (s -> b -> t)

Instances

#Setter' Source

type Setter' s a = Setter s s a a

#Setter Source

type Setter s t a b = Optic Function s t a b

A setter.

#Review' Source

type Review' s a = Review s s a a

#Review Source

type Review s t a b = Optic Tagged s t a b

A review.

#Re Source

newtype Re :: (Type -> Type -> Type) -> Type -> Type -> Type -> Type -> Typenewtype Re p s t a b

Constructors

  • Re (p b a -> p t s)

Instances

#Prism' Source

type Prism' s a = Prism s s a a

#Prism Source

type Prism s t a b = forall p. Choice p => Optic p s t a b

A prism.

#Optic' Source

type Optic' :: (Type -> Type -> Type) -> Type -> Type -> Typetype Optic' p s a = Optic p s s a a

#Optic Source

type Optic :: (Type -> Type -> Type) -> Type -> Type -> Type -> Type -> Typetype Optic p s t a b = p a b -> p s t

A general-purpose Data.Lens.

#Market Source

data Market a b s t

The Market profunctor characterizes a Prism.

Constructors

Instances

#Lens' Source

type Lens' s a = Lens s s a a

Lens' is a specialization of Lens. An optic of type Lens' can change only the value of its focus, not its type. As an example, consider the Lens _2, which has this type:

_2 :: forall s t a b. Lens (Tuple s a) (Tuple t b) a b

_2 can produce a Tuple Int String from a Tuple Int Int:

set _2 "NEW" (Tuple 1 2) == (Tuple 1 "NEW")

If we specialize _2's type with Lens', the following will not type check:

set (_2 :: Lens' (Tuple Int Int) Int) "NEW" (Tuple 1 2)
           ^^^^^^^^^^^^^^^^^^^^^^^^^

See Data.Lens.Getter and Data.Lens.Setter for functions and operators frequently used with lenses.

#Lens Source

type Lens s t a b = forall p. Strong p => Optic p s t a b

Given a type whose "focus element" always exists, a lens provides a convenient way to view, set, and transform that element.

For example, _2 is a tuple-specific Lens available from Data.Lens, so:

over _2 String.length $ Tuple "ignore" "four" == Tuple "ignore" 4

Note the result has a different type than the original tuple. That is, the four Lens type variables have been narrowed to:

  • s is Tuple String String
  • t is Tuple String Int
  • a is String
  • b is Int

See Data.Lens.Getter and Data.Lens.Setter for functions and operators frequently used with lenses.

#Iso' Source

type Iso' s a = Iso s s a a

#Iso Source

type Iso s t a b = forall p. Profunctor p => Optic p s t a b

A generalized isomorphism.

#IndexedTraversal' Source

type IndexedTraversal' i s a = IndexedTraversal i s s a a

#IndexedTraversal Source

type IndexedTraversal i s t a b = forall p. Wander p => IndexedOptic p i s t a b

An indexed traversal.

#IndexedSetter' Source

type IndexedSetter' i s a = IndexedSetter i s s a a

#IndexedSetter Source

type IndexedSetter i s t a b = IndexedOptic Function i s t a b

An indexed setter.

#IndexedOptic' Source

type IndexedOptic' :: (Type -> Type -> Type) -> Type -> Type -> Type -> Typetype IndexedOptic' p i s a = IndexedOptic p i s s a a

#IndexedOptic Source

type IndexedOptic :: (Type -> Type -> Type) -> Type -> Type -> Type -> Type -> Type -> Typetype IndexedOptic p i s t a b = Indexed p i a b -> p s t

An indexed optic.

#IndexedGetter' Source

type IndexedGetter' i s a = IndexedGetter i s s a a

#IndexedGetter Source

type IndexedGetter i s t a b = IndexedFold a i s t a b

An indexed getter.

#IndexedFold' Source

type IndexedFold' r i s a = IndexedFold r i s s a a

#IndexedFold Source

type IndexedFold r i s t a b = IndexedOptic (Forget r) i s t a b

An indexed fold.

#Indexed Source

newtype Indexed :: (Type -> Type -> Type) -> Type -> Type -> Type -> Typenewtype Indexed p i s t

Profunctor used for IndexedOptics.

Constructors

Instances

#Getter' Source

type Getter' s a = Getter s s a a

#Getter Source

type Getter s t a b = forall r. Fold r s t a b

A getter.

#Forget Source

newtype Forget :: forall k. Type -> Type -> k -> Typenewtype Forget r a b

Profunctor that forgets the b value and returns (and accumulates) a value of type r.

Forget r is isomorphic to Star (Const r), but can be given a Cochoice instance.

Constructors

Instances

#Fold' Source

type Fold' r s a = Fold r s s a a

#Fold Source

type Fold r s t a b = Optic (Forget r) s t a b

A fold.

#Exchange Source

data Exchange a b s t

The Exchange profunctor characterizes an Iso.

Constructors

Instances

#AnIso' Source

type AnIso' s a = AnIso s s a a

#AnIso Source

type AnIso s t a b = Optic (Exchange a b) s t a b

#ATraversal' Source

type ATraversal' s a = ATraversal s s a a

#ATraversal Source

type ATraversal s t a b = Optic (Bazaar Function a b) s t a b

#APrism' Source

type APrism' s a = APrism s s a a

#APrism Source

type APrism s t a b = Optic (Market a b) s t a b

#ALens' Source

type ALens' s a = ALens s s a a

#ALens Source

type ALens s t a b = Optic (Shop a b) s t a b

#AGetter' Source

type AGetter' s a = AGetter s s a a

#AGetter Source

type AGetter s t a b = Fold a s t a b

#Wander Source

class Wander :: (Type -> Type -> Type) -> Constraintclass (Strong p, Choice p) <= Wander p  where

Class for profunctors that support polymorphic traversals.

Members

  • wander :: forall s t a b. (forall f. Applicative f => (a -> f b) -> s -> f t) -> p a b -> p s t

Instances