Module

Data.SelectionFoldableWithData

#SelectionFoldableWithData

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

#IsSelected

type IsSelected = Boolean

A type alias used for better clarity in type signatures.

#fromFoldable

fromFoldable :: forall f d a. Foldable f => f a -> SelectionFoldableWithData f d a

Constructs a SelectionFoldableWithData from a Foldable structure of items.

#toFoldable

toFoldable :: forall f d a. Foldable f => SelectionFoldableWithData f d a -> f a

Extracts the Foldable structure of items from a SelectionFoldableWithData.

#select

select :: forall f d a. 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

selectWith :: forall f d a. 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

selectIndex :: forall i f d a. 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

selectWithIndex :: forall i f d a. 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

deselect :: forall f d a. SelectionFoldableWithData f d a -> SelectionFoldableWithData f d a

Clears the selection and its associated data.

#selected

selected :: forall f d a. SelectionFoldableWithData f d a -> Maybe (Tuple d a)

Returns the selected item and its associated data as a Tuple (if they exist).

#selected_

selected_ :: forall f d a. SelectionFoldableWithData f d a -> Maybe a

Returns the selected item (if it exists).

#mapSelected

mapSelected :: forall f d a e b. 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

foldrSelected :: forall f d a b. 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

foldrWithIndexSelected :: forall i f d a b. 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

foldlSelected :: forall f d a b. 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

foldlWithIndexSelected :: forall i f d a b. 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.

Modules