Officially out now: The TypeDB 3.0 Roadmap >>

Functions

Introduction

Functions provide powerful abstractions of query logic, and a cornerstone of the functional database programming model. Functions calls can be nested, recursive, negated, and they natively embed into TypeQL’s declarative patterns.

Function types

The following table illustrates the types of functions based on two dimensions: number of rows and number of columns returned.

Table 1. Categorizing functions based on their output type
Single output type Tuple of output types

output

up to 1 row

scalar function

type signature …​ → A

returns single $a

tuple function

type signature …​ → A, B

returns tuple $a, $b

output

multiple rows

(scalar) stream function

type signature …​ → { A }

returns stream { $a }

(tuple) stream function

type signature …​ → { A, B }

returns stream { $a, $b }

Explore functions

Learn how to write functions.

Learn how to work with stream-return functions.

Learn how to work with scalar functions.