<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
Source effect/Function.ts:3241 lines
export const const constant: <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)
constant = <function (type parameter) A in <A>(value: A): LazyArg<A>A>(value: Avalue: function (type parameter) A in <A>(value: A): LazyArg<A>A): type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) A in <A>(value: A): LazyArg<A>A> => () => value: AvalueReferenced by 18 symbols
Channel.runFoldEffectEffect.txExecutionPlan.CurrentMetadataFunction.constFalseFunction.constNullFunction.constTrueFunction.constUndefinedLayer.succeedContextLayer.syncContextQueue.collectRcMap.makeSchedule.CurrentMetadataSchedule.ScheduleSchedule.fibonacciSink.reduceWhileEffectSink.takeWhileEffectSink.takeWhileFilterEffectStream.scan