HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

  • Packagefocus-1.0.3.2
  • Exports34
  • LanguageHaskell2010
  • LicenceMIT
  • SourceFocus.hs
datadata Focus element (m :: Type -> Type) result
#

Abstraction over the modification of an element of a datastructure.

It is composable using the standard typeclasses, e.g.:

lookupAndDelete :: Monad m => Focus a m (Maybe a)
lookupAndDelete = lookup <* delete

Constructors

Instances4MonadTrans, Monad, Functor, Applicative
datadata Change a
#

What to do with the focused value.

The interpretation of the commands is up to the context APIs.

Constructors

  • Leave

    Produce no changes

  • Remove

    Delete it

  • Set a

    Set its value to the provided one

Instances6Functor, Eq, Ord, Show, Semigroup, Monoid

Pure functions

0 declarations

Reading functions

Modifying functions

valueaccessAndAdjust :: Monad m => (s -> a) -> (s -> s) -> Focus s m (Maybe a)
#

Same as all of the following expressions:

f g -> fmap (fmap f) lookup <* adjust g f g -> liftStateFn (f &&& g) f g -> liftStateFn ((,) $ f * g)

Construction utils

valuecases :: Monad m => (b, Change a) -> (a -> (b, Change a)) -> Focus a m b
#

Lift pure functions which handle the cases of presence and absence of the element.

valueunitCases :: Monad m => Change a -> (a -> Change a) -> Focus a m ()
#

Lift pure functions which handle the cases of presence and absence of the element and produce no result.

Monadic functions

0 declarations

Reading functions

Modifying functions

Construction utils

valuecasesM :: m (b, Change a) -> (a -> m (b, Change a)) -> Focus a m b
#

Lift monadic functions which handle the cases of presence and absence of the element.

valueunitCasesM :: Monad m => m (Change a) -> (a -> m (Change a)) -> Focus a m ()
#

Lift monadic functions which handle the cases of presence and absence of the element and produce no result.

Composition

1 declaration

Change-inspecting functions

7 declarations
valuetestingIfInserts :: Monad m => Focus a m b -> Focus a m (b, Bool)
#

Extends the output with a flag, signaling whether an item will be inserted. That is, it didn't exist before and a Set change is introduced.

valuetestingSizeChange
  1. :: Monad m
  2. => sizeChange

    Decreased

  3. -> sizeChange

    Didn't change

  4. -> sizeChange

    Increased

  5. -> Focus a m b
  6. -> Focus a m (b, sizeChange)
#

Extend the output with a flag, signaling how the size will be affected by the change.

STM

1 declaration