Hyperlinkv0.8.0-beta.28

Function

Function.constantconsteffect/Function.ts:324
<A>(value: A): LazyArg<A>

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)
constructors
export const constant = <A>(value: A): LazyArg<A> => () => value
Referenced by 18 symbols