This module exposes a list that has at most one selected item.
The invariants here:
Create a Selection a with nothing selected.
Convert a Selection list back to a regular list. This is useful for creating view functions, for example.
Mark an item as selected. This will select at most one item. Any previously selected item will be unselected.
fromList ["Burrito", "Chicken Wrap", "Taco Salad"]
|> select "Burrito"
|> selected --> Just "Burrito"Attempting to select an item that doesn't exist is a no-op.
fromList ["Burrito", "Chicken Wrap", "Taco Salad"]
|> select "Doner Kebab"
|> selected --> NothingDeselect any selected item. This is a no-op if nothing is selected in the first place.
Get the selected item, which might not exist.
fromList ["Burrito", "Chicken Wrap", "Taco Salad"]
|> select "Burrito"
|> selected --> Just "Burrito"Apply a function to all the items, including the currently selected item.
fromList [1, 2, 3]
|> map ((*) 2)
|> toList --> [2, 4, 6]
A list of items, one of which might be selected.