Skip to content

chain

Create a chain of function to run in order

93 bytes

Usage

Chaining functions will cause them to execute one after another, passing the output from each function as the input to the next, returning the final output at the end of the chain.

import * as
import _
_
from 'radashi'
const
const add: (y: number) => (x: number) => number
add
= (
y: number
y
: number) => (
x: number
x
: number) =>
x: number
x
+
y: number
y
const
const multiply: (y: number) => (x: number) => number
multiply
= (
y: number
y
: number) => (
x: number
x
: number) =>
x: number
x
*
y: number
y
const
const addFive: (x: number) => number
addFive
=
const add: (y: number) => (x: number) => number
add
(5)
const
const double: (x: number) => number
double
=
const multiply: (y: number) => (x: number) => number
multiply
(2)
const
const chained: (x: number) => number
chained
=
import _
_
.
chain<[x: number], number, number>(f1: (x: number) => number, f2: (arg: number) => number): (x: number) => number (+8 overloads)
export chain

Create a function that chains multiple functions together. The functions are called in order. Each function takes the result of the previous function as its first argument.

@seehttps://radashi.js.org/reference/curry/chain

@example

const myChainedFunc = chain(
(x) => x + 5,
(x) => x * 2,
)
myChainedFunc(0)
// => 10

@version12.1.0

chain
(
const addFive: (x: number) => number
addFive
,
const double: (x: number) => number
double
)
const chained: (x: number) => number
chained
(0) // => 10
const chained: (x: number) => number
chained
(7) // => 24

Example

import * as
import _
_
from 'radashi'
type
type Deity = {
name: string;
rank: number;
}
Deity
= {
name: string
name
: string
rank: number
rank
: number
}
const
const gods: Deity[]
gods
:
type Deity = {
name: string;
rank: number;
}
Deity
[] = [
{
rank: number
rank
: 8,
name: string
name
: 'Ra' },
{
rank: number
rank
: 7,
name: string
name
: 'Zeus' },
{
rank: number
rank
: 9,
name: string
name
: 'Loki' },
]
const
const getName: (god: Deity) => string
getName
= (
god: Deity
god
:
type Deity = {
name: string;
rank: number;
}
Deity
) =>
god: Deity
god
.
name: string
name
const
const upperCase: (text: string) => Uppercase<string>
upperCase
= (
text: string
text
: string) =>
text: string
text
.
String.toUpperCase(): string

Converts all the alphabetic characters in a string to uppercase.

toUpperCase
() as
type Uppercase<S extends string> = intrinsic

Convert string literal type to uppercase

Uppercase
<string>
const
const getUpperName: (god: Deity) => Uppercase<string>
getUpperName
=
import _
_
.
chain<[god: Deity], string, Uppercase<string>>(f1: (god: Deity) => string, f2: (arg: string) => Uppercase<string>): (god: Deity) => Uppercase<string> (+8 overloads)
export chain

Create a function that chains multiple functions together. The functions are called in order. Each function takes the result of the previous function as its first argument.

@seehttps://radashi.js.org/reference/curry/chain

@example

const myChainedFunc = chain(
(x) => x + 5,
(x) => x * 2,
)
myChainedFunc(0)
// => 10

@version12.1.0

chain
(
const getName: (god: Deity) => string
getName
,
const upperCase: (text: string) => Uppercase<string>
upperCase
)
const getUpperName: (god: Deity) => Uppercase<string>
getUpperName
(
const gods: Deity[]
gods
[0]) // => 'RA'
const gods: Deity[]
gods
.
Array<Deity>.map<Uppercase<string>>(callbackfn: (value: Deity, index: number, array: Deity[]) => Uppercase<string>, thisArg?: any): Uppercase<string>[]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
(
const getUpperName: (god: Deity) => Uppercase<string>
getUpperName
) // => ['RA', 'ZEUS', 'LOKI']