> For the complete documentation index, see [llms.txt](https://definiti.gitbook.io/definiti/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://definiti.gitbook.io/definiti/language-syntax/functions.md).

# Functions

## Function syntax

Functions are a way to structure your code and sometime reuse it. They already exist in nearly all languages.

Their syntax is the following:

```
def isNonEmpty(string: String): Boolean => {
  string.nonEmpty()
}
```

The parameter type and return type are both required. There is no type inference in function return types.

If you need to use generic types, you can do like the following:

```
def contains[A](list: List[A], element: A): Boolean => {
  list.contains(element)
}
```

## Return value of a function

In Definiti, all expressions return a value. The return type of the function is the return type of the last expression of the function. There is no `return` keyword you can use.

See [Expressions](/definiti/language-syntax/expressions.md) for more information.

## Restrictions

Functions can only exist as a first-class citizen. You cannot declare a function inside a type, verification or another function.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://definiti.gitbook.io/definiti/language-syntax/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
