Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- newtype Selection f b a = Selection {
- runSelection :: f (Either b a)
- newSelection :: Selectable s f => f a -> s b a
- forgetSelection :: Selectable s f => s a a -> f a
- select :: Selectable s f => (a -> Bool) -> s a a -> s a a
- include :: Selectable s f => (a -> Bool) -> s a a -> s a a
- exclude :: Selectable s f => (a -> Bool) -> s a a -> s a a
- selectAll :: Selectable s f => s a a -> s a a
- deselectAll :: Selectable s f => s a a -> s a a
- invertSelection :: Selectable s f => s b a -> s a b
- mapSelected :: Selectable s f => (a -> c) -> s b a -> s b c
- mapUnselected :: Selectable s f => (b -> c) -> s b a -> s c a
- getSelected :: (Selectable s f, Foldable f) => s b a -> [a]
- getUnselected :: (Selectable s f, Foldable f) => s b a -> [b]
- unify :: Selectable s f => (b -> c) -> (a -> c) -> s b a -> f c
- trans :: (Selectable s f, Selectable t g) => (forall c. f c -> g c) -> s b a -> t b a
- selectWithContext :: (Selectable s w, Comonad w) => (w a -> Bool) -> s a a -> s a a
Selection
newtype Selection f b a Source #
The simplest selection type
Selection | |
|
Functor f => Bifunctor (Selection f) Source # | Bifunctor over unselected ( |
Traversable f => Bitraversable (Selection f) Source # | Bitraversable over unselected and selected values respectively |
Foldable f => Bifoldable (Selection f) Source # | Bifoldable over unselected and selected values respectively |
Monad m => Monad (Selection m b) Source # | Selection is a monad over selected items when the underlying m is a Monad |
Functor f => Functor (Selection f b) Source # | |
Monad m => Applicative (Selection m b) Source # | |
Foldable f => Foldable (Selection f b) Source # | |
Eq (f (Either b a)) => Eq (Selection f b a) Source # | |
Show (f (Either b a)) => Show (Selection f b a) Source # | |
Selecting/Deselecting
Most selection combinators require that both the selected and unselected types be equal (i.e. Selection 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 :: Selectable s f => f a -> s b a Source #
Create a selection from a functor by selecting all values
forgetSelection :: Selectable s f => s a a -> f a Source #
Drops selection from your functor returning all values (selected or not).
forgetSelection
.newSelection
= id
forgetSelection
=unify
id id
select :: Selectable s f => (a -> Bool) -> s a a -> s a a Source #
Clear the selection then select only items which match a predicate.
select
f =include
f .deselectAll
deselectAll :: Selectable s f => s a a -> s a a Source #
Deselect all items in the container
deselectAll
=exclude
(const True)
invertSelection :: Selectable s f => s b a -> s a b Source #
Flip the selection, all selected are now unselected and vice versa.
mapSelected :: Selectable s f => (a -> c) -> s b a -> s b c Source #
Map over selected values
onSelected
= fmap
mapUnselected :: Selectable s f => (b -> c) -> s b a -> s c a Source #
Map over unselected values
onSelected
f =modifySelection
(fmap (first
f))
getSelected :: (Selectable s f, Foldable f) => s b a -> [a] Source #
Collect all selected values into a list. For more complex operations use foldMap.
getSelected
= foldMap (:[])
getUnselected :: (Selectable s f, Foldable f) => s b a -> [b] Source #
Collect all unselected values into a list. For more complex operations use operations from Bifoldable.
getUnselected
=getSelected
.invertSelection
unify :: Selectable s f => (b -> c) -> (a -> c) -> s b a -> f c Source #
Unify selected and unselected and forget the selection
unify
f g ==forgetSelection
.onUnselected
f .onSelected
g
trans :: (Selectable s f, Selectable t g) => (forall c. f c -> g c) -> s b a -> t b a Source #
Perform a natural transformation over the underlying container of a selectable
Comonad Combinators
selectWithContext :: (Selectable s w, Comonad w) => (w a -> Bool) -> s a a -> s a a Source #
Select values based on their context within a comonad. This combinator makes its selection by running the predicate using extend.