Problem
When writing mappings, want something that emulates the logic of a switch statement / conditional branching. Maybe this could be an enum that the Mapper class (and other related classes) cleans up
Requested feature
from pydian.dicts import SWAP
some_mapping = lambda d: {
"a": SWAP(get(d, 'some_field'), {
1: "one", # Handle specific cases (anything hashable)
2: "two",
str: "Got a str", # Handle classes
None: None # Handle base case
}, strict=True) # Default strict -- expect developer to handle all cases
}
Alternatives considered
Additional context
- Fun to keep the 4-letter acronyms. SWAP ~ Switch with advanced positioning
Problem
When writing mappings, want something that emulates the logic of a switch statement / conditional branching. Maybe this could be an enum that the Mapper class (and other related classes) cleans up
Requested feature
Alternatives considered
Additional context