> For the complete documentation index, see [llms.txt](https://hanfak.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanfak.gitbook.io/workspace/general-paradigms/programming-types/functional-programming/first-class-functions.md).

# First class functions

* an essential feature of functional language
* Functions are described as first-class when they can be treated like any other value: that is to say,
  * they can be dynamically assigned to a name or symbol at runtime
  * they can be stored in data structures
  * passed in via function arguments
  * returned as function return values
* Similar to how pointers work
* Also called Lambdas
  * lambdas are unnamed/annoymous functions
  * The point of a lambda function is where you need a function in that place and only there; since it is not needed anywhere else you simply define it right there. It doesn’t need a name.
    * If you did need to reuse it somewhere else then you would consider defining it as a named function and referencing it by name instead
* As function/lambda is passed as a variable (or is function form)
  * it is not called immediately
  * it can be called/invoked by whoever it was passed to
* First-class functions are also the means for achieving asynchronous I/O
  * allows to make non-blocking function call
  * you pass it a reference to a function for it to call you back on when it is done


---

# 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://hanfak.gitbook.io/workspace/general-paradigms/programming-types/functional-programming/first-class-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.
