Hyperlinkv0.8.0-beta.28

Function

Function.applyconsteffect/Function.ts:184
<A>(a: A): <B>(self: (a: A) => B) => B

Applies a function to a given value.

When to use

Use to pass a fixed value into a unary function, especially when the function is the value flowing through pipe.

Details

apply(a)(f) is equivalent to f(a).

Example (Applying an argument to a function)

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

assert.deepStrictEqual(pipe(String.length, Function.apply("hello")), 5)
combinatorspipe
export const apply = <A>(a: A) => <B>(self: (a: A) => B): B => self(a)