Data.Lens
- Package
- purescript-profunctor-lenses
- Repository
- purescript-contrib/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
Re-exports from Data.Lens.Fold
#sequenceOf_ Source
sequenceOf_ :: forall b a t s f. 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 Traversal
s.
#replicated Source
replicated :: forall r t b a. Monoid r => Int -> Fold r a b a t
Replicates the elements of a fold.
#productOf Source
productOf :: forall b a t s. Semiring a => Fold (Multiplicative a) s t a b -> s -> a
The product of all foci of a Fold
.
#orOf Source
orOf :: forall b a t s. HeytingAlgebra a => Fold (Disj a) s t a b -> s -> a
The disjunction of all foci of a Fold
.
#itraverseOf_ Source
itraverseOf_ :: forall r b a t s f i. 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.
#ifoldrOf Source
ifoldrOf :: forall r b a t s i. 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 r b a t s i. 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 b a t s i r. IndexedFold r i s t a b -> (i -> a -> r) -> s -> r
Fold map over an IndexedFold
.
#ianyOf Source
ianyOf :: forall r b a t s i. 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 r b a t s i. 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 r b a t s. HeytingAlgebra r => Fold (Conj r) s t a b -> s -> r
Determines whether a Fold
does not have a focus.
#has Source
has :: forall r b a t s. HeytingAlgebra r => Fold (Disj r) s t a b -> s -> r
Determines whether a Fold
has at least one focus.
#anyOf Source
anyOf :: forall r b a t s. 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 b a t s. HeytingAlgebra a => Fold (Conj a) s t a b -> s -> a
The conjunction of all foci of a Fold
.
#allOf Source
allOf :: forall r b a t s. HeytingAlgebra r => Fold (Conj r) s t a b -> (a -> r) -> s -> r
Whether all foci of a Fold
satisfy a predicate.
Re-exports from Data.Lens.Getter
#use Source
use :: forall m b a t s. MonadState s m => Getter s t a b -> m a
View the focus of a Getter
in the state of a monad.
#iview Source
iview :: forall b a t s i. 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 m b a t s i. 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 b a t s. AGetter s t a b -> Getter s t a b
Re-exports from Data.Lens.Grate
#zipFWithOf Source
zipFWithOf :: forall b a t s f. Optic (Costar f) s t a b -> (f a -> b) -> (f s -> t)
Re-exports from Data.Lens.Iso
#auf Source
auf :: forall p r e b a t s. Profunctor p => AnIso s t a b -> (p r a -> e -> b) -> p r s -> e -> t
Re-exports from Data.Lens.Lens
#lens Source
lens :: forall b a t s. (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
.
Re-exports from Data.Lens.Prism
#prism Source
prism :: forall b a t s. (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
#isn't Source
isn't :: forall r b a t s. HeytingAlgebra r => APrism s t a b -> s -> r
Ask if preview prism
would produce a Nothing
.
#is Source
is :: forall r b a t s. HeytingAlgebra r => APrism s t a b -> s -> r
Ask if preview prism
would produce a Just
.
#clonePrism Source
clonePrism :: forall b a t s. APrism s t a b -> Prism s t a b
Re-exports from Data.Lens.Setter
#subModifying Source
subModifying :: forall m a s. MonadState s m => Ring a => Setter' s a -> a -> m Unit
#mulModifying Source
mulModifying :: forall m a s. MonadState s m => Semiring a => Setter' s a -> a -> m Unit
#modifying Source
modifying :: forall m b a s. 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 b a t s i. 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 a t s. EuclideanRing a => Setter s t a a -> a -> s -> t
#divModifying Source
divModifying :: forall m a s. MonadState s m => EuclideanRing a => Setter' s a -> a -> m Unit
#disjOver Source
disjOver :: forall a t s. HeytingAlgebra a => Setter s t a a -> a -> s -> t
#disjModifying Source
disjModifying :: forall m a s. MonadState s m => HeytingAlgebra a => Setter' s a -> a -> m Unit
#conjOver Source
conjOver :: forall a t s. HeytingAlgebra a => Setter s t a a -> a -> s -> t
#conjModifying Source
conjModifying :: forall m a s. MonadState s m => HeytingAlgebra a => Setter' s a -> a -> m Unit
#assignJust Source
assignJust :: forall m b a s. MonadState s m => Setter s s a (Maybe b) -> b -> m Unit
#assign Source
assign :: forall m b a s. 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 a t s. Semigroup a => Setter s t a a -> a -> s -> t
#appendModifying Source
appendModifying :: forall m a s. MonadState s m => Semigroup a => Setter' s a -> a -> m Unit
#addModifying Source
addModifying :: forall m a s. MonadState s m => Semiring a => Setter' s a -> a -> m Unit
Re-exports from Data.Lens.Traversal
#traversed Source
traversed :: forall b a t. 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 b a t s f. 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 a t s f. 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 Fold
s.
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 b a t s i f. 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
.
#elementsOf Source
elementsOf :: forall a t s i p. 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 a t s p. 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
#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
isTuple String String
t
isTuple String Int
a
isString
b
isInt
See Data.Lens.Getter
and Data.Lens.Setter
for functions and operators
frequently used with lenses.
#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' p i s a = IndexedOptic p i s s a a
#IndexedOptic Source
type 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.
#Forget Source
- Modules
- Data.
Lens - Data.
Lens. At - Data.
Lens. Common - Data.
Lens. Fold - Data.
Lens. Fold. Partial - Data.
Lens. Getter - Data.
Lens. Grate - Data.
Lens. Index - Data.
Lens. Indexed - Data.
Lens. Internal. Bazaar - Data.
Lens. Internal. Exchange - Data.
Lens. Internal. Focusing - Data.
Lens. Internal. Forget - Data.
Lens. Internal. Grating - Data.
Lens. Internal. Indexed - Data.
Lens. Internal. Market - Data.
Lens. Internal. Re - Data.
Lens. Internal. Shop - Data.
Lens. Internal. Tagged - Data.
Lens. Internal. Wander - Data.
Lens. Internal. Zipping - Data.
Lens. Iso - Data.
Lens. Iso. Newtype - Data.
Lens. Lens - Data.
Lens. Lens. Product - Data.
Lens. Lens. Tuple - Data.
Lens. Lens. Unit - Data.
Lens. Lens. Void - Data.
Lens. Prism - Data.
Lens. Prism. Coproduct - Data.
Lens. Prism. Either - Data.
Lens. Prism. Maybe - Data.
Lens. Record - Data.
Lens. Setter - Data.
Lens. Traversal - Data.
Lens. Types - Data.
Lens. Zoom