TypeDB 3.0 is live! Get started for free.

Functions

Introduction

Functions provide powerful abstractions of query logic. They are a cornerstone of the functional query programming model, and generalize logic programs à la Datalog. Functions calls can be nested, recursive, and negated. There syntax natively embeds into TypeQL’s declarative pattern language.

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.