| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Focus
Synopsis
- data Focus element (m :: Type -> Type) result = Focus (m (result, Change element)) (element -> m (result, Change element))
- data Change a
- member :: forall (m :: Type -> Type) a. Monad m => Focus a m Bool
- lookup :: forall (m :: Type -> Type) a. Monad m => Focus a m (Maybe a)
- lookupWithDefault :: forall (m :: Type -> Type) a. Monad m => a -> Focus a m a
- delete :: forall (m :: Type -> Type) a. Monad m => Focus a m ()
- lookupAndDelete :: forall (m :: Type -> Type) a. Monad m => Focus a m (Maybe a)
- insert :: forall (m :: Type -> Type) a. Monad m => a -> Focus a m ()
- insertOrMerge :: forall (m :: Type -> Type) a. Monad m => (a -> a -> a) -> a -> Focus a m ()
- alter :: forall (m :: Type -> Type) a. Monad m => (Maybe a -> Maybe a) -> Focus a m ()
- adjust :: forall (m :: Type -> Type) a. Monad m => (a -> a) -> Focus a m ()
- update :: forall (m :: Type -> Type) a. Monad m => (a -> Maybe a) -> Focus a m ()
- accessAndAdjust :: forall (m :: Type -> Type) s a. Monad m => (s -> a) -> (s -> s) -> Focus s m (Maybe a)
- liftState :: forall (m :: Type -> Type) s a. Monad m => State s a -> Focus s m (Maybe a)
- liftStateFn :: forall (m :: Type -> Type) s a. Monad m => (s -> (a, s)) -> Focus s m (Maybe a)
- cases :: forall (m :: Type -> Type) b a. Monad m => (b, Change a) -> (a -> (b, Change a)) -> Focus a m b
- unitCases :: forall (m :: Type -> Type) a. Monad m => Change a -> (a -> Change a) -> Focus a m ()
- lookupWithDefaultM :: Monad m => m a -> Focus a m a
- insertM :: Monad m => m a -> Focus a m ()
- insertOrMergeM :: Monad m => (a -> a -> m a) -> m a -> Focus a m ()
- alterM :: Monad m => (Maybe a -> m (Maybe a)) -> Focus a m ()
- adjustM :: Monad m => (a -> m a) -> Focus a m ()
- updateM :: Monad m => (a -> m (Maybe a)) -> Focus a m ()
- casesM :: m (b, Change a) -> (a -> m (b, Change a)) -> Focus a m b
- unitCasesM :: Monad m => m (Change a) -> (a -> m (Change a)) -> Focus a m ()
- mappingInput :: forall (m :: Type -> Type) a b x. Monad m => (a -> b) -> (b -> a) -> Focus a m x -> Focus b m x
- extractingInput :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Maybe a)
- extractingChange :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Change a)
- projectingChange :: forall (m :: Type -> Type) a c b. Monad m => (Change a -> c) -> Focus a m b -> Focus a m (b, c)
- testingIfModifies :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Bool)
- testingIfRemoves :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Bool)
- testingIfInserts :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Bool)
- testingSizeChange :: forall (m :: Type -> Type) sizeChange a b. Monad m => sizeChange -> sizeChange -> sizeChange -> Focus a m b -> Focus a m (b, sizeChange)
- onTVarValue :: Focus a STM b -> Focus (TVar a) STM b
Documentation
data 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
Instances
| MonadTrans (Focus element) # | |
| Monad m => Applicative (Focus element m) # | |
Defined in Focus Methods pure :: a -> Focus element m a # (<*>) :: Focus element m (a -> b) -> Focus element m a -> Focus element m b # liftA2 :: (a -> b -> c) -> Focus element m a -> Focus element m b -> Focus element m c # (*>) :: Focus element m a -> Focus element m b -> Focus element m b # (<*) :: Focus element m a -> Focus element m b -> Focus element m a # | |
| Functor m => Functor (Focus element m) # | |
| Monad m => Monad (Focus element m) # | |
What to do with the focused value.
The interpretation of the commands is up to the context APIs.
Pure functions
Reading functions
member :: forall (m :: Type -> Type) a. Monad m => Focus a m Bool #
Reproduces the behaviour of
Data.Map.member.
lookup :: forall (m :: Type -> Type) a. Monad m => Focus a m (Maybe a) #
Reproduces the behaviour of
Data.Map.lookup.
lookupWithDefault :: forall (m :: Type -> Type) a. Monad m => a -> Focus a m a #
Reproduces the behaviour of
Data.Map.findWithDefault
with a better name.
Modifying functions
delete :: forall (m :: Type -> Type) a. Monad m => Focus a m () #
Reproduces the behaviour of
Data.Map.delete.
insert :: forall (m :: Type -> Type) a. Monad m => a -> Focus a m () #
Reproduces the behaviour of
Data.Map.insert.
insertOrMerge :: forall (m :: Type -> Type) a. Monad m => (a -> a -> a) -> a -> Focus a m () #
Reproduces the behaviour of
Data.Map.insertWith
with a better name.
alter :: forall (m :: Type -> Type) a. Monad m => (Maybe a -> Maybe a) -> Focus a m () #
Reproduces the behaviour of
Data.Map.alter.
adjust :: forall (m :: Type -> Type) a. Monad m => (a -> a) -> Focus a m () #
Reproduces the behaviour of
Data.Map.adjust.
update :: forall (m :: Type -> Type) a. Monad m => (a -> Maybe a) -> Focus a m () #
Reproduces the behaviour of
Data.Map.update.
accessAndAdjust :: forall (m :: Type -> Type) s a. Monad m => (s -> a) -> (s -> s) -> Focus s m (Maybe a) #
liftState :: forall (m :: Type -> Type) s a. Monad m => State s a -> Focus s m (Maybe a) #
Lift a pure state monad.
liftStateFn :: forall (m :: Type -> Type) s a. Monad m => (s -> (a, s)) -> Focus s m (Maybe a) #
Lift a pure state-monad-like function.
Construction utils
cases :: forall (m :: Type -> Type) b a. 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.
unitCases :: forall (m :: Type -> Type) a. 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
Reading functions
lookupWithDefaultM :: Monad m => m a -> Focus a m a #
A monadic version of lookupWithDefault.
Modifying functions
insertOrMergeM :: Monad m => (a -> a -> m a) -> m a -> Focus a m () #
A monadic version of insertOrMerge.
Construction utils
casesM :: 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.
unitCasesM :: 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
mappingInput :: forall (m :: Type -> Type) a b x. Monad m => (a -> b) -> (b -> a) -> Focus a m x -> Focus b m x #
Map the Focus input.
Change-inspecting functions
extractingInput :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Maybe a) #
Extends the output with the input.
extractingChange :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Change a) #
Extends the output with the change performed.
projectingChange :: forall (m :: Type -> Type) a c b. Monad m => (Change a -> c) -> Focus a m b -> Focus a m (b, c) #
Extends the output with a projection on the change that was performed.
testingIfModifies :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Bool) #
Extends the output with a flag,
signaling whether a change, which is not Leave, has been introduced.
testingIfRemoves :: forall (m :: Type -> Type) a b. Monad m => Focus a m b -> Focus a m (b, Bool) #
Extends the output with a flag,
signaling whether the Remove change has been introduced.
testingIfInserts :: forall (m :: Type -> Type) a b. 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.
Arguments
| :: forall (m :: Type -> Type) sizeChange a b. Monad m | |
| => sizeChange | Decreased |
| -> sizeChange | Didn't change |
| -> sizeChange | Increased |
| -> Focus a m b | |
| -> Focus a m (b, sizeChange) |
Extend the output with a flag, signaling how the size will be affected by the change.