Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- newtype Selection f b a = Selection {
- unwrapSelection :: f (Either b a)
- type Selection' f a = Selection f a a
- modifySelection :: Functor f => (f (Either b a) -> g (Either d c)) -> Selection f b a -> Selection g d c
- newSelection :: Functor f => f a -> Selection f b a
- forgetSelection :: Functor f => Selection f a a -> f a
- select :: Functor f => (a -> Bool) -> Selection f a a -> Selection f a a
- include :: Functor f => (a -> Bool) -> Selection f a a -> Selection f a a
- exclude :: Functor f => (a -> Bool) -> Selection f a a -> Selection f a a
- selectAll :: Functor f => Selection f a a -> Selection f a a
- deselectAll :: Functor f => Selection f a a -> Selection f a a
- invertSelection :: Functor f => Selection f b a -> Selection f a b
- mapSelected :: Functor f => (a -> c) -> Selection f b a -> Selection f b c
- mapUnselected :: Functor f => (b -> c) -> Selection f b a -> Selection f c a
- getSelected :: Foldable f => Selection f b a -> [a]
- getUnselected :: (Foldable f, Functor f) => Selection f b a -> [b]
- unify :: Functor f => (b -> c) -> (a -> c) -> Selection f b a -> f c
- trans :: Functor f => (forall c. f c -> g c) -> Selection f b a -> Selection g b a
- selectWithContext :: Comonad w => (w a -> Bool) -> Selection w a a -> Selection w a a
Selection
newtype Selection f b a Source #
A selection wraps a Functor f
and has an unselected type b
and a selected type a
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 # | |
Traversable f => Traversable (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 # | |
type Selection' f a = Selection f a a Source #
A type alias for selections with the same unselected/selected types
modifySelection :: Functor f => (f (Either b a) -> g (Either d c)) -> Selection f b a -> Selection g d c Source #
Modify the underlying representation of a selection
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 :: Functor f => f a -> Selection f b a Source #
Create a selection from a functor by selecting all values
forgetSelection :: Functor f => Selection f a a -> f a Source #
Drops selection from your functor returning all values (selected or not).
forgetSelection
.newSelection
= id
forgetSelection
=unify
id id
select :: Functor f => (a -> Bool) -> Selection f a a -> Selection f a a Source #
Clear the selection then select only items which match a predicate.
select
f =include
f .deselectAll
deselectAll :: Functor f => Selection f a a -> Selection f a a Source #
Deselect all items in the container
deselectAll
=exclude
(const True)
invertSelection :: Functor f => Selection f b a -> Selection f a b Source #
Flip the selection, all selected are now unselected and vice versa.
mapSelected :: Functor f => (a -> c) -> Selection f b a -> Selection f b c Source #
Map over selected values
mapSelected
= fmap
mapUnselected :: Functor f => (b -> c) -> Selection f b a -> Selection f c a Source #
Map over unselected values
mapUnselected
=first
getSelected :: Foldable f => Selection f b a -> [a] Source #
Collect all selected values into a list. For more complex operations use foldMap.
getSelected
= foldMap (:[])
getUnselected :: (Foldable f, Functor f) => Selection f b a -> [b] Source #
Collect all unselected values into a list. For more complex operations use operations from Bifoldable.
getUnselected
=getSelected
.invertSelection
unify :: Functor f => (b -> c) -> (a -> c) -> Selection f b a -> f c Source #
Unify selected and unselected and forget the selection
unify
f g ==forgetSelection
.onUnselected
f .onSelected
g
trans :: Functor f => (forall c. f c -> g c) -> Selection f b a -> Selection g b a Source #
Perform a natural transformation over the underlying container of a selectable