Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type View s a = forall p. (Strong p, forall x. Contravariant (p x)) => Optic' p s a
- type AView s a = Optic' (Star (Const a)) s a
- type Ixview i s a = forall p. (Strong p, forall x. Contravariant (p x)) => IndexedOptic' p i s a
- type AIxview r i s a = IndexedOptic' (Star (Const (Maybe i, r))) i s a
- type PrimView s t a b = forall p. (Profunctor p, forall x. Contravariant (p x)) => Optic p s t a b
- type Review t b = forall p. (Costrong p, Bifunctor p) => Optic' p t b
- type AReview t b = Optic' Tagged t b
- type Cxview k t b = forall p. (Costrong p, Bifunctor p) => CoindexedOptic' p k t b
- type ACxview k t b = CoindexedOptic' Tagged k t b
- type PrimReview s t a b = forall p. (Profunctor p, Bifunctor p) => Optic p s t a b
- to :: (s -> a) -> PrimView s t a b
- ixto :: (s -> (i, a)) -> Ixview i s a
- from :: (b -> t) -> PrimReview s t a b
- cxfrom :: ((k -> b) -> t) -> Cxview k t b
- cloneView :: AView s a -> PrimView s s a a
- cloneReview :: AReview t b -> PrimReview t t b b
- like :: a -> PrimView s t a b
- ixlike :: i -> a -> Ixview i s a
- relike :: t -> PrimReview s t a b
- cxlike :: t -> Cxview k t b
- toProduct :: AView s a1 -> AView s a2 -> PrimView s t (a1, a2) b
- fromSum :: AReview t b1 -> AReview t b2 -> PrimReview s t a (b1 + b2)
- withPrimView :: APrimView r s t a b -> (a -> r) -> s -> r
- withPrimReview :: APrimReview s t a b -> (t -> r) -> b -> r
- (^.) :: s -> AView s a -> a
- (^%) :: Monoid i => s -> AIxview a i s a -> (Maybe i, a)
- view :: MonadReader s m => AView s a -> m a
- ixview :: MonadReader s m => Monoid i => AIxview a i s a -> m (Maybe i, a)
- views :: MonadReader s m => Optic' (Star (Const r)) s a -> (a -> r) -> m r
- ixviews :: MonadReader s m => Monoid i => IndexedOptic' (Star (Const r)) i s a -> (i -> a -> r) -> m r
- use :: MonadState s m => AView s a -> m a
- ixuse :: MonadState s m => Monoid i => AIxview a i s a -> m (Maybe i, a)
- uses :: MonadState s m => Optic' (Star (Const r)) s a -> (a -> r) -> m r
- ixuses :: MonadState s m => Monoid i => IndexedOptic' (Star (Const r)) i s a -> (i -> a -> r) -> m r
- (#^) :: AReview t b -> b -> t
- review :: MonadReader b m => AReview t b -> m t
- cxview :: MonadReader b m => ACxview k t b -> m (k -> t)
- reviews :: MonadReader b m => AReview t b -> (t -> r) -> m r
- cxviews :: MonadReader b m => ACxview k t b -> ((k -> t) -> r) -> m r
- reuse :: MonadState b m => AReview t b -> m t
- reuses :: MonadState b m => AReview t b -> (t -> r) -> m r
- cxuse :: MonadState b m => ACxview k t b -> m (k -> t)
- cxuses :: MonadState b m => ACxview k t b -> ((k -> t) -> r) -> m r
- throws :: MonadIO m => Exception e => AReview e b -> b -> m r
- throws_ :: MonadIO m => Exception e => AReview e () -> m r
- throwsTo :: MonadIO m => Exception e => ThreadId -> AReview e b -> b -> m ()
- newtype Star (f :: Type -> Type) d c = Star {
- runStar :: d -> f c
- newtype Tagged (s :: k) b :: forall k. k -> Type -> Type = Tagged {
- unTagged :: b
Types
type Ixview i s a = forall p. (Strong p, forall x. Contravariant (p x)) => IndexedOptic' p i s a Source #
type PrimView s t a b = forall p. (Profunctor p, forall x. Contravariant (p x)) => Optic p s t a b Source #
type ACxview k t b = CoindexedOptic' Tagged k t b Source #
type PrimReview s t a b = forall p. (Profunctor p, Bifunctor p) => Optic p s t a b Source #
Constructors
from :: (b -> t) -> PrimReview s t a b Source #
cloneReview :: AReview t b -> PrimReview t t b b Source #
TODO: Document
Optics
relike :: t -> PrimReview s t a b Source #
Primitive operators
withPrimView :: APrimView r s t a b -> (a -> r) -> s -> r Source #
TODO: Document
withPrimReview :: APrimReview s t a b -> (t -> r) -> b -> r Source #
TODO: Document
Operators
(^.) :: s -> AView s a -> a infixl 8 Source #
An infix alias for view
. Dual to #
.
Fixity and semantics are such that subsequent field accesses can be
performed with (.
).
>>>
("hello","world") ^. t22
"world"
>>>
import Data.Complex
>>>
((0, 1 :+ 2), 3) ^. t21 . t22 . to magnitude
2.23606797749979
(^.
) :: s ->View
s a -> a (^.
) ::Monoid
m => s ->Fold
s m -> m (^.
) :: s ->Iso'
s a -> a (^.
) :: s ->Lens'
s a -> a (^.
) :: s ->Coprism'
s a -> a (^.
) ::Monoid
m => s ->Traversal'
s m -> m
(^%) :: Monoid i => s -> AIxview a i s a -> (Maybe i, a) infixl 8 Source #
Bring the index and value of a indexed optic into the current environment as a pair.
This a flipped, infix variant of ixview
and an indexed variant of ^.
.
The fixity and semantics are such that subsequent field accesses can be
performed with (.
).
The result probably doesn't have much meaning when applied to an Ixfold
.
view :: MonadReader s m => AView s a -> m a Source #
ixview :: MonadReader s m => Monoid i => AIxview a i s a -> m (Maybe i, a) Source #
Bring the index and value of a indexed optic into the current environment as a pair.
>>>
ixview ixfirst ("foo", 42)
(Just (),"foo")
>>>
ixview (ixat 3 . ixfirst) [(0,'f'),(1,'o'),(2,'o'),(3,'b'),(4,'a'),(5,'r') :: (Int, Char)]
(Just 3,3)
In order to ixview
a Choice
optic (e.g. Ixtraversal0
, Ixtraversal
, Ixfold
, etc),
a must have a Monoid
instance:
>>>
ixview (ixat 0) ([] :: [Int])
(Nothing,0)>>>
ixview (ixat 0) ([1] :: [Int])
(Just 0,1)
Note when applied to a Ixtraversal
or Ixfold
, then ixview
will return a monoidal
summary of the indices tupled with a monoidal summary of the values:
>>>
(ixview @_ @_ @Int @Int) ixtraversed [1,2,3,4]
(Just 6,10)
views :: MonadReader s m => Optic' (Star (Const r)) s a -> (a -> r) -> m r Source #
Map each part of a structure viewed to a semantic edixtor combinator.
'views o f ≡ withFold o f'foldMap
=views
folding'
>>>
views both id (["foo"], ["bar", "baz"])
["foo","bar","baz"]
views
::AView
s a -> (a -> r) -> s -> rviews
::Iso'
s a -> (a -> r) -> s -> rviews
::Lens'
s a -> (a -> r) -> s -> rviews
::Coprism'
s a -> (a -> r) -> s -> rviews
::Monoid
r =>Traversal'
s a -> (a -> r) -> s -> rviews
::Semigroup
r =>Traversal1'
s a -> (a -> r) -> s -> rviews
::Monoid
r =>Fold
s a -> (a -> r) -> s -> rviews
::Semigroup
r =>Fold1
s a -> (a -> r) -> s -> r
ixviews :: MonadReader s m => Monoid i => IndexedOptic' (Star (Const r)) i s a -> (i -> a -> r) -> m r Source #
Bring a function of the index and value of an indexed optic into the current environment.
ixviews
≡ iwithFold
>>>
ixviews (ixat 2) (-) ([0,1,2] :: [Int])
0
In order to ixviews
a Choice
optic (e.g. Ixtraversal0
, Ixtraversal
, Ixfold
, etc),
a must have a Monoid
instance (here from the rings
package):
>>>
ixviews (ixat 3) (flip const) ([1] :: [Int])
0
Use ixview
if there is a need to disambiguate between mempty
as a miss vs. as a return value.
use :: MonadState s m => AView s a -> m a Source #
TODO: Document
ixuse :: MonadState s m => Monoid i => AIxview a i s a -> m (Maybe i, a) Source #
Bring the index and value of an indexed optic into the current environment as a pair.
uses :: MonadState s m => Optic' (Star (Const r)) s a -> (a -> r) -> m r Source #
Use the target of a Lens
, Iso
or
View
in the current state, or use a summary of a
Fold
or Traversal
that
points to a monoidal value.
>>>
evalState (uses t21 length) ("hello","world!")
5
uses
::MonadState
s m =>Iso'
s a -> (a -> r) -> m ruses
::MonadState
s m =>View
s a -> (a -> r) -> m ruses
::MonadState
s m =>Lens'
s a -> (a -> r) -> m ruses
::MonadState
s m =>Coprism'
s a -> (a -> r) -> m ruses
::MonadState
s m =>Monoid
r =>Traversal'
s a -> (a -> r) -> m ruses
::MonadState
s m =>Monoid
r =>Fold
s a -> (a -> r) -> m r
uses
::MonadState
s m =>Getting
r s t a b -> (a -> r) -> m r
ixuses :: MonadState s m => Monoid i => IndexedOptic' (Star (Const r)) i s a -> (i -> a -> r) -> m r Source #
Bring a function of the index and value of an indexed optic into the current environment.
(#^) :: AReview t b -> b -> t infixr 8 Source #
An infix variant of review
. Dual to ^.
.
from
f #^ x ≡ f x o #^ x ≡ x^.
re
o
This is commonly used when using a Prism
as a smart constructor.
>>>
left #^ 4
Left 4
(#^) ::Iso'
s a -> a -> s (#^) ::Prism'
s a -> a -> s (#^) ::Colens'
s a -> a -> s (#^) ::Review
s a -> a -> s (#^) ::Equality'
s a -> a -> s
review :: MonadReader b m => AReview t b -> m t Source #
cxview :: MonadReader b m => ACxview k t b -> m (k -> t) Source #
Bring a function of the index of a co-indexed optic into the current environment.
reviews :: MonadReader b m => AReview t b -> (t -> r) -> m r Source #
Turn an optic around and look through the other end, applying a function.
reviews
≡views
.
re
reviews
(from
f) g ≡ g.
f
>>>
reviews left isRight "mustard"
False
>>>
reviews (from succ) (*2) 3
8
reviews
::Iso'
t b -> (t -> r) -> b -> rreviews
::Prism'
t b -> (t -> r) -> b -> rreviews
::Colens'
t b -> (t -> r) -> b -> r
cxviews :: MonadReader b m => ACxview k t b -> ((k -> t) -> r) -> m r Source #
Bring a continuation of the index of a co-indexed optic into the current environment.
cxviews :: ACxview k t b -> ((k -> t) -> r) -> b -> r
reuse :: MonadState b m => AReview t b -> m t Source #
Turn an optic around and use
a value (or the current environment) through it the other way.
reuse
≡use
.
re
reuse
.
from
≡gets
>>>
evalState (reuse left) 5
Left 5
>>>
evalState (reuse (from succ)) 5
6
reuse
::MonadState
a m =>Iso'
s a -> m sreuse
::MonadState
a m =>Prism'
s a -> m sreuse
::MonadState
a m =>Colens'
s a -> m s
reuses :: MonadState b m => AReview t b -> (t -> r) -> m r Source #
Turn an optic around and use
the current state through it the other way, applying a function.
reuses
≡uses
.
re
reuses
(from
f) g ≡gets
(g.
f)
>>>
evalState (reuses left isLeft) (5 :: Int)
True
reuses
::MonadState
a m =>Iso'
s a -> (s -> r) -> m rreuses
::MonadState
a m =>Prism'
s a -> (s -> r) -> m rreuses
::MonadState
a m =>Prism'
s a -> (s -> r) -> m r
cxuse :: MonadState b m => ACxview k t b -> m (k -> t) Source #
TODO: Document
cxuses :: MonadState b m => ACxview k t b -> ((k -> t) -> r) -> m r Source #
TODO: Document
MonadIO
throws_ :: MonadIO m => Exception e => AReview e () -> m r Source #
Variant of throws
for error constructors with no arguments.
Carriers
newtype Star (f :: Type -> Type) d c #
Lift a Functor
into a Profunctor
(forwards).
Instances
Functor f => Representable (Star f) | |
Applicative f => Choice (Star f) | |
Traversable f => Cochoice (Star f) | |
Distributive f => Closed (Star f) | |
Defined in Data.Profunctor.Closed | |
Functor m => Strong (Star m) | |
Functor f => Profunctor (Star f) | |
Defined in Data.Profunctor.Types | |
Functor f => Sieve (Star f) f | |
Defined in Data.Profunctor.Sieve | |
Monad f => Category (Star f :: Type -> Type -> Type) | |
Monad f => Monad (Star f a) | |
Functor f => Functor (Star f a) | |
Applicative f => Applicative (Star f a) | |
Contravariant f => Contravariant (Star f a) Source # | |
Alternative f => Alternative (Star f a) | |
MonadPlus f => MonadPlus (Star f a) | |
Distributive f => Distributive (Star f a) | |
Defined in Data.Profunctor.Types | |
Apply f => Apply (Star f a) Source # | |
type Rep (Star f) | |
Defined in Data.Profunctor.Rep |
newtype Tagged (s :: k) b :: forall k. k -> Type -> Type #
A
value is a value Tagged
s bb
with an attached phantom type s
.
This can be used in place of the more traditional but less safe idiom of
passing in an undefined value with the type, because unlike an (s -> b)
,
a
can't try to use the argument Tagged
s bs
as a real value.
Moreover, you don't have to rely on the compiler to inline away the extra argument, because the newtype is "free"
Tagged
has kind k -> * -> *
if the compiler supports PolyKinds
, therefore
there is an extra k
showing in the instance haddocks that may cause confusion.