effect-io-ai

Package: effect
Module: Function

Function.compose

Composes two functions, ab and bc into a single function that takes in an argument a of type A and returns a result of type C. The result is obtained by first applying the ab function to a and then applying the bc function to the result of ab.

When to use

Use to compose exactly two unary functions into a reusable unary function.

Example (Composing two functions)

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

const increment = (n: number) => n + 1
const square = (n: number) => n * n

assert.strictEqual(Function.compose(increment, square)(2), 9)

See

Signature

declare const compose: { <B, C>(bc: (b: B) => C): <A>(self: (a: A) => B) => (a: A) => C; <A, B, C>(self: (a: A) => B, bc: (b: B) => C): (a: A) => C; }

Source

Since v2.0.0