effect-io-ai

Package: effect
Module: Function

Function.constant

Creates a zero-argument function that always returns the provided value.

When to use

Use when you need a thunk or callback that returns the same value on every invocation.

Example (Creating a constant thunk)

import { Function } from "effect"
import * as assert from "node:assert"

const constNull = Function.constant(null)

assert.deepStrictEqual(constNull(), null)
assert.deepStrictEqual(constNull(), null)

Signature

declare const constant: <A>(value: A) => LazyArg<A>

Source

Since v2.0.0