Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newtype SelectionT f b a = SelectionT {
- runSelectionT :: f (Either b a)
- newSelection :: Functor f => f a -> SelectionT f () a
- forgetSelection :: Functor f => SelectionT f a a -> f a
- select :: Functor f => (a -> Bool) -> SelectionT f a a -> SelectionT f a a
- include :: Functor f => (a -> Bool) -> SelectionT f a a -> SelectionT f a a
- exclude :: Functor f => (a -> Bool) -> SelectionT f a a -> SelectionT f a a
- selectAll :: Functor f => SelectionT f a a -> SelectionT f a a
- deselectAll :: Functor f => SelectionT f a a -> SelectionT f a a
- invertSelection :: Functor f => SelectionT f b a -> SelectionT f a b
- onSelected :: Functor f => (a -> c) -> SelectionT f b a -> SelectionT f b c
- onUnselected :: Functor f => (b -> c) -> SelectionT f b a -> SelectionT f c a
- getSelected :: Foldable f => SelectionT f b a -> [a]
- getUnselected :: (Functor f, Foldable f) => SelectionT f b a -> [b]
- selectWithContext :: Comonad w => (w a -> Bool) -> SelectionT w a a -> SelectionT w a a
SelectionT
newtype SelectionT f b a Source #
A monad transformer for performing actions over selected values. Combinators are provided to select specific values within the underlying Functor. This transformer is isomorphic to EitherT, but interprets semantics differently, thus providing a different understanding and different combinators.
SelectionT | |
|
Functor f => Bifunctor (SelectionT f) Source # | Bifunctor over unselected ( |
Traversable f => Bitraversable (SelectionT f) Source # | Bitraversable over unselected and selected values respectively |
Foldable f => Bifoldable (SelectionT f) Source # | Bifoldable over unselected and selected values respectively |
Monad f => Monad (SelectionT f b) Source # | SelectionT is a monad over selected items when the underlying m is a Monad |
Functor f => Functor (SelectionT f b) Source # | |
Applicative f => Applicative (SelectionT f b) Source # | |
Foldable f => Foldable (SelectionT f b) Source # | |
Eq (f (Either b a)) => Eq (SelectionT f b a) Source # | |
Show (f (Either b a)) => Show (SelectionT f b a) Source # | |
Selecting/Deselecting
Most selection combinators require that both the selected and unselected types be equal (i.e. SelectionT f a a); this is necessary since items will switch their selection status. Your selected and unselected types may diverge, but you'll need to unify them in order to extract your underlying functor.
newSelection :: Functor f => f a -> SelectionT f () a Source #
Create a selection from a functor by selecting all values
forgetSelection :: Functor f => SelectionT f a a -> f a Source #
Drops selection from your functor returning all values (selected or not).
forgetSelection . newSelection = id
select :: Functor f => (a -> Bool) -> SelectionT f a a -> SelectionT f a a Source #
Clear the selection then select only items which match a predicate.
select f = include f . deselectAll
include :: Functor f => (a -> Bool) -> SelectionT f a a -> SelectionT f a a Source #
Add items which match a predicate to the current selection
include f . select g = select (a -> f a || g a)
exclude :: Functor f => (a -> Bool) -> SelectionT f a a -> SelectionT f a a Source #
Remove items which match a predicate to the current selection
exclude f . select g = select (a -> f a && not (g a))
selectAll :: Functor f => SelectionT f a a -> SelectionT f a a Source #
Select all items in the container
selectAll = include (const True)
deselectAll :: Functor f => SelectionT f a a -> SelectionT f a a Source #
Deselect all items in the container
deselectAll = exclude (const True)
invertSelection :: Functor f => SelectionT f b a -> SelectionT f a b Source #
Flip the selection, all selected are now unselected and vice versa.
onSelected :: Functor f => (a -> c) -> SelectionT f b a -> SelectionT f b c Source #
Map over selected values
onSelected = fmap
onUnselected :: Functor f => (b -> c) -> SelectionT f b a -> SelectionT f c a Source #
Map over unselected values
onSelected = first
getSelected :: Foldable f => SelectionT f b a -> [a] Source #
Collect all selected values into a list. For more complex operations use foldMap.
getSelected = foldMap (:[])
getUnselected :: (Functor f, Foldable f) => SelectionT f b a -> [b] Source #
Collect all unselected values into a list. For more complex operations use operations from Bifoldable.
getUnselected = foldMap (:[]) . invertSelection
Comonad Combinators
selectWithContext :: Comonad w => (w a -> Bool) -> SelectionT w a a -> SelectionT w a a Source #
Select values based on their context within a comonad. This combinator makes its selection by running the predicate using extend.