Skip to main content
Module

x/core_fn/deps.ts>curry

A collection of built-in object method and property as currying function
Latest
variable curry
import { curry } from "https://deno.land/x/core_fn@v1.0.0-beta.16/deps.ts";

Creates a function that accepts arguments of fn and either invokes fn returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining fn arguments, and so on.

Examples

Example 1

const replace = (from: string, to: string, val: string) => val.replace(from, to)
const curriedReplace = curry(replace)
const curriedReplace('hello', 'hi', 'hello world') // 'hi world'
const curriedReplace('hello')('hi', 'hello world') // 'hi world'
const curriedReplace('hello')('hi')('hello world') // 'hi world'

type

<T extends unknown[], R>(fn: (...args: T) => R) => T["length"] extends 0 ? () => R : Curried<T, R>