Skip to main content
Module

x/froebel/function.ts>pipe

A strictly typed utility library.
Go to Latest
variable pipe
import { pipe } from "https://deno.land/x/froebel@v0.23.1/function.ts";

Given a list of functions returns a function that will execute the given functions one after another, always passing the result of the previous function as an argument to the next function.

If one of the given functions returns a promise, the promise will be resolved before being passed to the next function.

Examples

Example 1

const join = (...chars: string[]) => chars.join('')
pipe(join, parseInt)('1', '2', '3')  // -> 123

const square = (n: number) => n ** 2

// this is equivalent to: square(square(square(2)))
pipe(square, square, square)(2)  // -> 256

// also works with promises:
fetchNumber :: async () => Promise<number>
pipe(fetchNumber, n => n.toString())  // async () => Promise<string>

type

<T extends [λ, ...λ[]]>(...funs: PipeReturn<T> extends never ? never : T) => unknown