Closed antoine-gallix closed 9 months ago
Here's one approach:
spec = Switch({"condition": T.get("this")}, default=T.get("that"))
Another way to go about it is use something that will always be True to make a default inside the Switch dict:
spec = Switch({"condition": T.get("this"), Val(True): T.get("that")})
You can also use glom.And
/ glom.Or
to achieve what you want through short-circuit logic:
And("condition", T.get("this"), default=T.get("that"))
Or(And("condition", T.get("this")), T.get("that"))
This expression looks most concise to me: And("condition", T.get("this"), default=T.get("that"))
-- although it is also 100% valid to embed that spec()
function you wrote inside a spec.
Whatever is most readable!
Thanks!
I've tried many forms of spec, but I haven't been able, just by reading the documentation of
Switch
, to replicate the following logic with it:What's the solution?