extend

.extend name:{String} body:{Lambda} -> Void

Defines a custom function that extends an existing one by name, wrapping its output.

The body lambda receives an optional first parameter (conventionally called super), which holds the result of the original function for the same arguments, followed by the original function's parameters in their declared order. All wrapper parameters are optional, regardless of whether the original parameters are.

.function {greet}
name:
Hello, .name

.extend {greet}
super:
.super::uppercase

.greet {World}

Output: HELLO, WORLD

The wrapper can also reference the original parameters by name to alter the behavior conditionally:

.extend {greet}
super name:
.if {.name::equals {World}}
.super::uppercase
.ifnot {.name::equals {World}}
.super

In implicit form, the parameters can be accessed positionally:

.extend {greet}
.1::uppercase

Parameters

name

name of the existing function to extend

body

wrapper content. Its first parameter is bound to the original function's output; any further explicit parameters must match the original function's parameter names

Throws

if no function named name exists, or if any explicit parameter beyond super does not match an original parameter

Wiki page

extending-functions