extend
Defines a custom function that extends an existing one by name, wrapping its output.
Within the body, the original function is exposed as .super: calling it invokes the original with the arguments the wrapper was called with. The body's explicit parameters, if any, must match the original function's parameters by name and let the wrapper read those same arguments. All wrapper parameters are optional, regardless of whether the original parameters are.
.function {greet}
name:
Hello, .name
.extend {greet}
.super::uppercase
.greet {World}Output:
HELLO, WORLD
The wrapper can reference the original parameters by name to alter the behavior conditionally:
.extend {greet}
name:
.if {.name::equals {World}}
.super::uppercase
.ifnot {.name::equals {World}}
.superBecause .super is the original function itself, it accepts the same arguments. Anything you pass overrides the corresponding argument the wrapper was called with, while anything you leave out falls through unchanged:
.extend {greet}
name:
.super name:{.name::uppercase}
.greet {John}Output:
Hello, JOHN
Parameters
name of the existing function to extend
- Likely a body argument
wrapper content. Its explicit parameters, if any, must match the original function's parameter names. .super is implicitly available within the body
Throws
if no function named name exists, or if any explicit parameter does not match an original parameter