Data.SelectionFoldableWithData
- Package
- purescript-selection-foldable
- Repository
- jamieyung/purescript-selection-foldable
#SelectionFoldableWithData Source
data SelectionFoldableWithData f d a
A Foldable where at most one item is selected, and the selected item has some extra data associated with it. The selected item is guaranteed to be in the Foldable structure. However, no guarantees are made regarding uniqueness of the items (see the README for more info).
The data constructor is kept private in order to maintain the desired invariants.
f
is the type of the Foldable that will contain the items.d
is the type of the data associated with the optionally selected item.a
is the type of the items.
Instances
(Eq (f a), Eq d, Eq a) => Eq (SelectionFoldableWithData f d a)
(Show (f a), Show d, Show a) => Show (SelectionFoldableWithData f d a)
(Functor f) => Functor (SelectionFoldableWithData f d)
(Foldable f) => Foldable (SelectionFoldableWithData f d)
(FoldableWithIndex i f) => FoldableWithIndex i (SelectionFoldableWithData f d)
(Functor f, Compactable f) => Compactable (SelectionFoldableWithData f d)
(Filterable f) => Filterable (SelectionFoldableWithData f d)
#IsSelected Source
type IsSelected = Boolean
A type alias used for better clarity in type signatures.
#fromFoldable Source
fromFoldable :: forall a d f. Foldable f => f a -> SelectionFoldableWithData f d a
Constructs a SelectionFoldableWithData
from a Foldable structure of
items.
#toFoldable Source
toFoldable :: forall a d f. Foldable f => SelectionFoldableWithData f d a -> f a
Extracts the Foldable structure of items from a
SelectionFoldableWithData
.
#select Source
select :: forall a d f. Foldable f => Eq a => d -> a -> SelectionFoldableWithData f d a -> SelectionFoldableWithData f d a
Selects the first element a
such that a == x
. If such an element is
found, it is selected and the provided d
is used as the associated data.
If not, nothing happens.
#selectWith Source
selectWith :: forall a d f. Foldable f => (a -> Maybe d) -> SelectionFoldableWithData f d a -> SelectionFoldableWithData f d a
Selects the first element a
such that p a == true
. If such an element
is found, it is selected and the provided function f
is used to calculate
the d
to be used as the associated data. If not, nothing happens.
#selectIndex Source
selectIndex :: forall a d f i. FoldableWithIndex i f => Eq i => (a -> d) -> i -> SelectionFoldableWithData f d a -> SelectionFoldableWithData f d a
Selects the element at index i'
such that i' == i
. If such an element
is found, it is selected and the provided function p
is used to calculate
the d
to be used as the associated data. If not, nothing happens.
#selectWithIndex Source
selectWithIndex :: forall a d f i. FoldableWithIndex i f => (i -> a -> Maybe d) -> SelectionFoldableWithData f d a -> SelectionFoldableWithData f d a
Selects the first element a
such that p i a == Just d
where i
is the
index of a
. If such an element is found, it is selected and the provided
d
is used as the associated data. If not, nothing happens.
#deselect Source
deselect :: forall a d f. SelectionFoldableWithData f d a -> SelectionFoldableWithData f d a
Clears the selection and its associated data.
#selected Source
selected :: forall a d f. SelectionFoldableWithData f d a -> Maybe (Tuple d a)
Returns the selected item and its associated data as a Tuple (if they exist).
#selected_ Source
selected_ :: forall a d f. SelectionFoldableWithData f d a -> Maybe a
Returns the selected item (if it exists).
#mapSelected Source
mapSelected :: forall b e a d f. Foldable f => Functor f => Eq a => { rest :: a -> b, sel :: Tuple d a -> Tuple e b } -> SelectionFoldableWithData f d a -> SelectionFoldableWithData f e b
If there exist multiple elements a
such that p a == true
, the function
will be invoked with true
as the first argument. No guarantee of
uniqueness is made; that is left up to the user.
#foldrSelected Source
foldrSelected :: forall b a d f. Foldable f => Eq a => { rest :: a -> b -> b, sel :: Tuple d a -> b -> b } -> b -> SelectionFoldableWithData f d a -> b
Performs a foldr, using the provided functions to transform the items and
the data. The sel
function is used for all items a
that are equal to
the selected item, and the rest
function is used for the other items.
#foldrWithIndexSelected Source
foldrWithIndexSelected :: forall b a d f i. FoldableWithIndex i f => Eq a => { rest :: i -> a -> b -> b, sel :: i -> Tuple d a -> b -> b } -> b -> SelectionFoldableWithData f d a -> b
Performs a foldrWithIndex, using the provided functions to transform the
items and the data. The sel
function is used for all items a
that are
equal to the selected item, and the rest
function is used for the other
items.
#foldlSelected Source
foldlSelected :: forall b a d f. Foldable f => Eq a => { rest :: b -> a -> b, sel :: b -> Tuple d a -> b } -> b -> SelectionFoldableWithData f d a -> b
Performs a foldl, using the provided functions to transform the items and
the data. The sel
function is used for all items a
that are equal to
the selected item, and the rest
function is used for the other items.
#foldlWithIndexSelected Source
foldlWithIndexSelected :: forall b a d f i. FoldableWithIndex i f => Eq a => { rest :: i -> b -> a -> b, sel :: i -> b -> Tuple d a -> b } -> b -> SelectionFoldableWithData f d a -> b
Performs a foldlWithIndex, using the provided functions to transform the
items and the data. The sel
function is used for all items a
that are
equal to the selected item, and the rest
function is used for the other
items.