Selection state for lists and tables. Pure data structure supporting single, multi, and range selection modes.
Modes
:single-- at most one item selected at a time.:multi-- multiple items selectable;extend: trueadds to the set.:range-- like multi, butrange_select/2selects a contiguous slice of theorderlist between the anchor and the target.
Example
sel = Plushie.Selection.new(mode: :multi, order: ["a", "b", "c", "d"])
sel = Plushie.Selection.select(sel, "b")
sel = Plushie.Selection.select(sel, "d", extend: true)
Plushie.Selection.selected(sel)
#=> MapSet.new(["b", "d"])
Summary
Functions
Clears all selected items and resets the anchor.
Removes id from the selection.
Creates a new selection state.
Selects all items in order between the current anchor and id
(inclusive). If there is no anchor, selects only id.
Selects id. In :single mode, replaces the selection. In :multi
and :range modes, replaces unless extend: true is passed, in which
case id is added to the existing selection.
Selects all items in order.
Returns the MapSet of currently selected item IDs.
Returns true if id is currently selected.
Toggles id in the selection. If already selected, removes it;
otherwise adds it. In :single mode, toggling a selected item
clears the selection entirely.
Types
Functions
Clears all selected items and resets the anchor.
Removes id from the selection.
Creates a new selection state.
Options
:mode-- selection mode::single(default),:multi, or:range.:order-- ordered list of item IDs for range selection.
Selects all items in order between the current anchor and id
(inclusive). If there is no anchor, selects only id.
Requires order to have been set at creation time via new/1.
Selects id. In :single mode, replaces the selection. In :multi
and :range modes, replaces unless extend: true is passed, in which
case id is added to the existing selection.
Sets the anchor to id for subsequent range selections.
Selects all items in order.
Requires order to have been set at creation time via new/1.
Returns the MapSet of currently selected item IDs.
Returns true if id is currently selected.
Toggles id in the selection. If already selected, removes it;
otherwise adds it. In :single mode, toggling a selected item
clears the selection entirely.