Rebus.Choice
- Package
- purescript-rebus
- Repository
- afcondon/purescript-rebus
Rebus.Choice — this one is chosen, that one is dealt.
A hash has no idea what a flame means. Most things want exactly that: an arbitrary picture that is a name and nothing more. But some things in a subject DO have a picture that is theirs (heat is the flame, sunlight is the sun), and for those the caller says so and the hash is not consulted.
The two halves go together. An icon that is placed by declaration should not
also turn up by chance, so withdraw the declared icons from the deck the
rest are dealt from (Rebus.Deck.without; chosenIcons collects them).
#Choice Source
data ChoiceWhat the caller says about ONE thing: deal it, or it is these icons.
Chosen carries icon NAMES and not a finished glyph, and that is the
decision that keeps the alias honest. A glyph's colours are a function of
its icon names and of nothing else, which is why thirteen typed characters
redraw the same picture. A chosen glyph that brought colours of its own
would be a picture its alias could not reproduce, and a chosen alias that
disagreed with its icons would be worse. So a choice names icons; the
palette colours them as it colours every other; the alias spells them.
The names are free: they need not be in the deck (the point of withdrawing
a loaded icon is to place it here), nor in any deck Rebus ships (an icon
drawn specially for oil or for money is a name like any other, as long as
the renderer can find it). One to five names with no hyphen in them is a
glyph whose alias reads back; Chosen [] is a glyph of no icons, which is
what was asked for.
There is no type parameter and no function inside, though the sketch this
grew from had both (Choice (a -> Rebus)). A choice is about one thing, so
the function belongs outside it: a policy for a whole subject is an
ordinary a -> Choice, which can say Dealt for one thing and Chosen for
the next, and which chooseAmong builds from a table.
Constructors
Instances
#rebusOfChoice Source
rebusOfChoice :: Width -> Deck -> Choice -> String -> GlyphThe glyph of one thing, given what was said about it: its canonical text dealt from the deck at the width, or the chosen icons as they stand.
rebusOfChoice width deck Dealt IS rebusOfWithWidth width deck. The width
applies to what is dealt; a choice is as wide as the icons it names.
#chooseAmong Source
chooseAmong :: forall key. Eq key => Array { icons :: Array String, key :: key } -> key -> ChoiceA policy from a table: the things that have icons of their own, and everything else dealt. The common case, so that a subject's vocabulary is one literal:
meaning = chooseAmong
[ { key: "heat", icons: [ "fire" ] }
, { key: "sunlight", icons: [ "sun" ] }
]
meaning "heat" == Chosen [ "fire" ]
meaning "boiler" == Dealt
The first entry for a key wins.