Search
ctrl/
Ask AI
Light
Dark
System

User-Defined Functions

Subtopics

Function parameters in EdgeDB are positional by default, meaning that the arguments are evaluated according to their order when calling a function. However, parameters can also be prefixed with named only which allows the input to be optional. That is, the input is only evaluated when the user passes in a parameter that is named.

It is possible to create a function that requires certain arguments to be named only. The user of the function must select by name which arguments to enter, which in turn gives the compiler the needed information to allow the named arguments to be omitted. This approach is useful if a function has many parameters that can be omitted. Let's create a function that adds a prefix and suffix to a string:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input

And now we can try it out:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input
Input
Run
Output Objects
Press the 'Run' button to evaluate the input

Note that positional arguments cannot come after named only arguments as the optional input for named only makes it impossible for the compiler to determine the position of a positional argument. In other words, make sure that named only parameters are at the end.