Skip to main content
List is an immutable linked list data structure.

Type Definition

type List<A> = Cons<A> | Nil

Constructors

nil

Creates an empty List.
const nil: <A = never>() => List<A>

cons

Prepends an element to a List.
const cons: <A>(head: A, tail: List<A>) => List<A>

make

Creates a List from values.
const make: <As extends ReadonlyArray<any>>(...as: As) => List<As[number]>

Operations

Retrieves the first element.
const head: <A>(self: List<A>) => Option<A>

tail

Retrieves all but the first element.
const tail: <A>(self: List<A>) => Option<List<A>>

map

Transforms elements in a List.
const map: <A, B>(f: (a: A) => B) => (self: List<A>) => List<B>

Example

import { List } from "effect"

const list = List.make(1, 2, 3).pipe(
  List.prepend(0),
  List.map(n => n * 2)
)

console.log(List.head(list)) // Some(0)

Build docs developers (and LLMs) love