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

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:

• Exactly one result a with Iso, Lens, ReversedPrism and Getter.
• At most one result Maybe a with Prism, AffineTraversal and AffineFold.
• Monoidal summary of all results Monoid a => a with Traversal and Fold.

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

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.