# Functions

## [](#_introduction)Introduction

Functions provide powerful abstractions of query logic. They are a cornerstone of the functional [query programming model](../data-model/index.md), and generalize logic programs à la Datalog. Functions calls can be nested, recursive, and negated. Their syntax natively embeds into TypeQL’s declarative pattern language.

## [](#fun_types)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)Explore functions

[Writing functions](writing/index.md)

Learn how to write functions.

[Stream functions](stream/index.md)

Learn how to work with stream-return functions.

[Scalar and tuple functions](scalar/index.md)

Learn how to work with scalar functions.

[Functions v/s rules](functions-vs-rules/index.md)

How do functions differ from TypeDB 2 rules?

[End](../pipelines/end/index.md) [Writing functions](writing/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/typeql-reference/modules/ROOT/pages/functions/index.adoc) Edit this page on GitHub.