Module

Control.Comonad.Store

Package
purescript-transformers
Repository
purescript/purescript-transformers

This module defines the Store comonad.

#Store Source

type Store s = StoreT s Identity

The Store comonad is a synonym for the StoreT comonad transformer, applied to the Identity monad.

#runStore Source

runStore :: forall s a. Store s a -> Tuple (s -> a) s

Unwrap a value in the Store comonad.

#store Source

store :: forall s a. (s -> a) -> s -> Store s a

Create a value in context in the Store comonad.

Re-exports from Control.Comonad.Store.Class

#ComonadStore Source

class (Comonad w) <= ComonadStore s w | w -> s where

The ComonadStore type class represents those monads which support local position information via pos and peek.

  • pos reads the current position.
  • peek reads the value at the specified position in the specified context.

An implementation is provided for StoreT.

Laws:

  • pos (extend _ x) = pos x
  • peek (pos x) x = extract x

For example:

blur :: forall w. (ComonadStore Number w) -> w Number -> w Number
blur = extend \r -> (peeks (\n -> n - 1) r + peeks (\n -> n + 1) r) / 2)

Members

  • pos :: forall a. w a -> s
  • peek :: forall a. s -> w a -> a

Instances

#seeks Source

seeks :: forall s a w. ComonadStore s w => (s -> s) -> w a -> w a

Reposition the focus at the specified position, which depends on the current position.

#seek Source

seek :: forall s a w. ComonadStore s w => s -> w a -> w a

Reposition the focus at the specified position.

#peeks Source

peeks :: forall s a w. ComonadStore s w => (s -> s) -> w a -> a

Extract a value from a position which depends on the current position.

#experiment Source

experiment :: forall f a w s. ComonadStore s w => Functor f => (s -> f s) -> w a -> f a

Extract a collection of values from positions which depend on the current position.

Re-exports from Control.Comonad.Store.Trans

#StoreT Source

newtype StoreT s w a

The store comonad transformer.

This comonad transformer extends the context of a value in the base comonad so that the value depends on a position of type s.

The ComonadStore type class describes the operations supported by this comonad.

Constructors

Instances

#runStoreT Source

runStoreT :: forall s w a. StoreT s w a -> Tuple (w (s -> a)) s

Unwrap a value in the StoreT comonad.