3 ms·
This pattern also nicely expands when you need to select from more than 2 values. And it lets you keep the mapping as a data instead of turning it into logic.
by jusssi 5y ago
This pattern also nicely expands when you need to select from more than 2 values. And it lets you keep the mapping as a data instead of turning it into logic.
{"a": 1, "b": 2}.get(selector(), default_value)
for the else-case.