PipeableReusable prototype that implements Pipeable.pipe.
When to use
Use when classes or object prototypes can reuse this value when they need the
standard pipe implementation backed by pipeArguments.
export const const Prototype: Pipeableconst Prototype: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Reusable prototype that implements Pipeable.pipe.
When to use
Use when classes or object prototypes can reuse this value when they need the
standard pipe implementation backed by pipeArguments.
Prototype: Pipeable = {
Pipeable.pipe<A>(this: A): A (+21 overloads)pipe() {
return const pipeArguments: <Pipeable>(
self: Pipeable,
args: IArguments
) => unknown
Applies a pipe method's variadic arguments to an initial value from left
to right.
When to use
Use to implement a custom .pipe(...) method from JavaScript's arguments
object.
Details
This helper is intended for implementing Pipeable.pipe methods that
receive JavaScript's arguments object. With no functions it returns the
original value; otherwise it feeds each result into the next function.
Example (Implementing a pipe method)
import { Pipeable } from "effect"
class NumberBox {
constructor(readonly value: number) {}
pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
return Pipeable.pipeArguments(this.value, arguments) as number
}
}
const result = new NumberBox(5).pipe(
(n) => n + 2,
(n) => n * 3
)
console.log(result) // 21
pipeArguments(this, function (local var) arguments: IArgumentsarguments)
}
}