The section “Branching without if” is a bit confusing, because it is unclear if those examples work or need more code.
The relevant context is the earlier definition of @if_.
@if_
def if_(condition): def decorator(c): if condition: return c.then() else: return c.else_() return decorator
So
def if_(condition): def decorator(c): return [c.then, c.else][not condition]() return decorator
would have the same behavior, and does not itself have an if statement. I’ve implemented if without using if.
if
The relevant context is the earlier definition of
@if_
.So
would have the same behavior, and does not itself have an
if
statement. I’ve implementedif
without usingif
.