optics-extra-0.1: Extra utilities and instances for optics-core

Safe HaskellNone
LanguageHaskell2010

Optics.View

Description

EXPERIMENTAL

Synopsis

Documentation

class ViewableOptic k r where Source #

Generalized view (even more powerful than view from the lens library).

View the value(s) pointed to by an optic.

The type of the result depends on the optic. You get:

When in doubt, use specific, flavour restricted versions. This function is mostly useful for things such as passthrough.

Associated Types

type ViewResult k r :: * Source #

Methods

gview :: MonadReader s m => Optic' k is s r -> m (ViewResult k r) Source #

gviews :: MonadReader s m => Optic' k is s a -> (a -> r) -> m (ViewResult k r) Source #

Instances
ViewableOptic An_Iso r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult An_Iso r :: Type Source #

Methods

gview :: MonadReader s m => Optic' An_Iso is s r -> m (ViewResult An_Iso r) Source #

gviews :: MonadReader s m => Optic' An_Iso is s a -> (a -> r) -> m (ViewResult An_Iso r) Source #

ViewableOptic A_Lens r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult A_Lens r :: Type Source #

Methods

gview :: MonadReader s m => Optic' A_Lens is s r -> m (ViewResult A_Lens r) Source #

gviews :: MonadReader s m => Optic' A_Lens is s a -> (a -> r) -> m (ViewResult A_Lens r) Source #

ViewableOptic A_Prism r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult A_Prism r :: Type Source #

Methods

gview :: MonadReader s m => Optic' A_Prism is s r -> m (ViewResult A_Prism r) Source #

gviews :: MonadReader s m => Optic' A_Prism is s a -> (a -> r) -> m (ViewResult A_Prism r) Source #

ViewableOptic An_AffineTraversal r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult An_AffineTraversal r :: Type Source #

Monoid r => ViewableOptic A_Traversal r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult A_Traversal r :: Type Source #

Methods

gview :: MonadReader s m => Optic' A_Traversal is s r -> m (ViewResult A_Traversal r) Source #

gviews :: MonadReader s m => Optic' A_Traversal is s a -> (a -> r) -> m (ViewResult A_Traversal r) Source #

ViewableOptic A_ReversedPrism r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult A_ReversedPrism r :: Type Source #

ViewableOptic A_Getter r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult A_Getter r :: Type Source #

Methods

gview :: MonadReader s m => Optic' A_Getter is s r -> m (ViewResult A_Getter r) Source #

gviews :: MonadReader s m => Optic' A_Getter is s a -> (a -> r) -> m (ViewResult A_Getter r) Source #

ViewableOptic An_AffineFold r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult An_AffineFold r :: Type Source #

Monoid r => ViewableOptic A_Fold r Source # 
Instance details

Defined in Optics.View

Associated Types

type ViewResult A_Fold r :: Type Source #

Methods

gview :: MonadReader s m => Optic' A_Fold is s r -> m (ViewResult A_Fold r) Source #

gviews :: MonadReader s m => Optic' A_Fold is s a -> (a -> r) -> m (ViewResult A_Fold r) Source #

use :: (ViewableOptic k a, MonadState s m) => Optic' k is s a -> m (ViewResult k a) Source #

Use the target of a Lens, Iso, or Getter in the current state, or use a summary of a Fold or Traversal that points to a monoidal value.

>>> evalState (use _1) ('a','b')
'a'
>>> evalState (use _2) ("hello","world")
"world"

uses :: (ViewableOptic k r, MonadState s m) => Optic' k is s a -> (a -> r) -> m (ViewResult k r) Source #

Use the target of a Lens, Iso or Getter in the current state, or use a summary of a Fold or Traversal that points to a monoidal value.

>>> evalState (uses _1 length) ("hello","world")
5

listening :: (ViewableOptic k r, MonadWriter s m) => Optic' k is s r -> m a -> m (a, ViewResult k r) Source #

This is a generalized form of listen that only extracts the portion of the log that is focused on by a Getter. If given a Fold or a Traversal then a monoidal summary of the parts of the log that are visited will be returned.

listenings :: (ViewableOptic k r, MonadWriter s m) => Optic' k is s a -> (a -> r) -> m b -> m (b, ViewResult k r) Source #

This is a generalized form of listen that only extracts the portion of the log that is focused on by a Getter. If given a Fold or a Traversal then a monoidal summary of the parts of the log that are visited will be returned.