From 2bb91d1e15ec62bfa762bb17aec6c97305b94692 Mon Sep 17 00:00:00 2001 From: gcanti Date: Sun, 29 Jan 2023 09:06:35 +0100 Subject: [PATCH] Function: flip apply --- .changeset/plenty-bats-try.md | 5 ++ docs/modules/Either.ts.md | 10 ++-- docs/modules/Function.ts.md | 23 ++++++-- docs/modules/Option.ts.md | 48 +++++++-------- src/Either.ts | 10 ++-- src/Function.ts | 20 +++++-- src/Option.ts | 48 +++++++-------- test/Function.ts | 108 +++++++++++++++++----------------- 8 files changed, 148 insertions(+), 124 deletions(-) create mode 100644 .changeset/plenty-bats-try.md diff --git a/.changeset/plenty-bats-try.md b/.changeset/plenty-bats-try.md new file mode 100644 index 000000000..d02914d45 --- /dev/null +++ b/.changeset/plenty-bats-try.md @@ -0,0 +1,5 @@ +--- +"@fp-ts/core": minor +--- + +Function: flip apply diff --git a/docs/modules/Either.ts.md b/docs/modules/Either.ts.md index 7ea4acd33..a787d4819 100644 --- a/docs/modules/Either.ts.md +++ b/docs/modules/Either.ts.md @@ -1205,8 +1205,8 @@ const onLeft = (errors: ReadonlyArray): string => `Errors: ${errors.join const onRight = (value: number): string => `Ok: ${value}` -assert.strictEqual(pipe(E.right(1), E.match(onLeft, onRight)), 'Ok: 1') -assert.strictEqual(pipe(E.left(['error 1', 'error 2']), E.match(onLeft, onRight)), 'Errors: error 1, error 2') +assert.deepStrictEqual(pipe(E.right(1), E.match(onLeft, onRight)), 'Ok: 1') +assert.deepStrictEqual(pipe(E.left(['error 1', 'error 2']), E.match(onLeft, onRight)), 'Errors: error 1, error 2') ``` Added in v1.0.0 @@ -1404,9 +1404,9 @@ import * as E from '@fp-ts/core/Either' const f = E.exists((n: number) => n > 2) -assert.strictEqual(f(E.left('a')), false) -assert.strictEqual(f(E.right(1)), false) -assert.strictEqual(f(E.right(3)), true) +assert.deepStrictEqual(f(E.left('a')), false) +assert.deepStrictEqual(f(E.right(1)), false) +assert.deepStrictEqual(f(E.right(3)), true) ``` Added in v1.0.0 diff --git a/docs/modules/Function.ts.md b/docs/modules/Function.ts.md index f7e99655a..182037955 100644 --- a/docs/modules/Function.ts.md +++ b/docs/modules/Function.ts.md @@ -184,10 +184,21 @@ Added in v1.0.0 ## apply +Apply a function to a given value. + **Signature** ```ts -export declare const apply: (a: A) => (self: (a: A) => B) => B +export declare const apply: (self: (a: A) => B) => (a: A) => B +``` + +**Example** + +```ts +import { pipe, apply } from '@fp-ts/core/Function' +import { increment } from '@fp-ts/core/Number' + +assert.deepStrictEqual(pipe(2, apply(increment)), 3) ``` Added in v1.0.0 @@ -302,7 +313,7 @@ import { flip } from '@fp-ts/core/Function' const f = (a: number) => (b: string) => a - b.length -assert.strictEqual(flip(f)('aaa')(2), -1) +assert.deepStrictEqual(flip(f)('aaa')(2), -1) ``` Added in v1.0.0 @@ -387,7 +398,7 @@ const double = (n: number): number => n * 2 const f = flow(len, double) -assert.strictEqual(f('aaa'), 6) +assert.deepStrictEqual(f('aaa'), 6) ``` Added in v1.0.0 @@ -662,10 +673,10 @@ const len = (s: string): number => s.length const double = (n: number): number => n * 2 // without pipe -assert.strictEqual(double(len('aaa')), 6) +assert.deepStrictEqual(double(len('aaa')), 6) // with pipe -assert.strictEqual(pipe('aaa', len, double), 6) +assert.deepStrictEqual(pipe('aaa', len, double), 6) ``` Added in v1.0.0 @@ -687,7 +698,7 @@ import { tupled } from '@fp-ts/core/Function' const add = tupled((x: number, y: number): number => x + y) -assert.strictEqual(add([1, 2]), 3) +assert.deepStrictEqual(add([1, 2]), 3) ``` Added in v1.0.0 diff --git a/docs/modules/Option.ts.md b/docs/modules/Option.ts.md index 8c7effa35..928989ffa 100644 --- a/docs/modules/Option.ts.md +++ b/docs/modules/Option.ts.md @@ -502,14 +502,14 @@ export declare const getOrElse: (onNone: any) => (self: Option) => B | import { some, none, getOrElse } from '@fp-ts/core/Option' import { pipe } from '@fp-ts/core/Function' -assert.strictEqual( +assert.deepStrictEqual( pipe( some(1), getOrElse(() => 0) ), 1 ) -assert.strictEqual( +assert.deepStrictEqual( pipe( none(), getOrElse(() => 0) @@ -635,8 +635,8 @@ export declare const isNone: (self: Option) => self is None ```ts import { some, none, isNone } from '@fp-ts/core/Option' -assert.strictEqual(isNone(some(1)), false) -assert.strictEqual(isNone(none()), true) +assert.deepStrictEqual(isNone(some(1)), false) +assert.deepStrictEqual(isNone(none()), true) ``` Added in v1.0.0 @@ -656,9 +656,9 @@ export declare const isOption: (input: unknown) => input is Option ```ts import { some, none, isOption } from '@fp-ts/core/Option' -assert.strictEqual(isOption(some(1)), true) -assert.strictEqual(isOption(none()), true) -assert.strictEqual(isOption({}), false) +assert.deepStrictEqual(isOption(some(1)), true) +assert.deepStrictEqual(isOption(none()), true) +assert.deepStrictEqual(isOption({}), false) ``` Added in v1.0.0 @@ -678,8 +678,8 @@ export declare const isSome: (self: Option) => self is Some ```ts import { some, none, isSome } from '@fp-ts/core/Option' -assert.strictEqual(isSome(some(1)), true) -assert.strictEqual(isSome(none()), false) +assert.deepStrictEqual(isSome(some(1)), true) +assert.deepStrictEqual(isSome(none()), false) ``` Added in v1.0.0 @@ -970,8 +970,8 @@ export declare const getOrNull: (self: Option) => A | null import { some, none, getOrNull } from '@fp-ts/core/Option' import { pipe } from '@fp-ts/core/Function' -assert.strictEqual(pipe(some(1), getOrNull), 1) -assert.strictEqual(pipe(none(), getOrNull), null) +assert.deepStrictEqual(pipe(some(1), getOrNull), 1) +assert.deepStrictEqual(pipe(none(), getOrNull), null) ``` Added in v1.0.0 @@ -1014,8 +1014,8 @@ export declare const getOrUndefined: (self: Option) => A | undefined import { some, none, getOrUndefined } from '@fp-ts/core/Option' import { pipe } from '@fp-ts/core/Function' -assert.strictEqual(pipe(some(1), getOrUndefined), 1) -assert.strictEqual(pipe(none(), getOrUndefined), undefined) +assert.deepStrictEqual(pipe(some(1), getOrUndefined), 1) +assert.deepStrictEqual(pipe(none(), getOrUndefined), undefined) ``` Added in v1.0.0 @@ -1246,7 +1246,7 @@ export declare const match: (onNone: any, onSome: (a: A) => C) => ( import { some, none, match } from '@fp-ts/core/Option' import { pipe } from '@fp-ts/core/Function' -assert.strictEqual( +assert.deepStrictEqual( pipe( some(1), match( @@ -1257,7 +1257,7 @@ assert.strictEqual( 'a some containing 1' ) -assert.strictEqual( +assert.deepStrictEqual( pipe( none(), match( @@ -1402,11 +1402,11 @@ import * as N from '@fp-ts/core/Number' import { pipe } from '@fp-ts/core/Function' const O = liftOrder(N.Order) -assert.strictEqual(O.compare(none(), none()), 0) -assert.strictEqual(O.compare(none(), some(1)), -1) -assert.strictEqual(O.compare(some(1), none()), 1) -assert.strictEqual(O.compare(some(1), some(2)), -1) -assert.strictEqual(O.compare(some(1), some(1)), 0) +assert.deepStrictEqual(O.compare(none(), none()), 0) +assert.deepStrictEqual(O.compare(none(), some(1)), -1) +assert.deepStrictEqual(O.compare(some(1), none()), 1) +assert.deepStrictEqual(O.compare(some(1), some(2)), -1) +assert.deepStrictEqual(O.compare(some(1), some(1)), 0) ``` Added in v1.0.0 @@ -1543,21 +1543,21 @@ export declare const exists: (predicate: any) => (self: Option) => boolean import { some, none, exists } from '@fp-ts/core/Option' import { pipe } from '@fp-ts/core/Function' -assert.strictEqual( +assert.deepStrictEqual( pipe( some(1), exists((n) => n > 0) ), true ) -assert.strictEqual( +assert.deepStrictEqual( pipe( some(1), exists((n) => n > 1) ), false ) -assert.strictEqual( +assert.deepStrictEqual( pipe( none(), exists((n) => n > 0) @@ -1615,7 +1615,7 @@ import { some, none, reduceAll } from '@fp-ts/core/Option' import { pipe } from '@fp-ts/core/Function' const iterable = [some(1), none(), some(2), none()] -assert.strictEqual( +assert.deepStrictEqual( pipe( iterable, reduceAll(0, (b, a) => b + a) diff --git a/src/Either.ts b/src/Either.ts index eed8e11ae..9b78b7f45 100644 --- a/src/Either.ts +++ b/src/Either.ts @@ -664,14 +664,14 @@ export const Foldable: foldable.Foldable = { * * const onRight = (value: number): string => `Ok: ${value}` * - * assert.strictEqual( + * assert.deepStrictEqual( * pipe( * E.right(1), * E.match(onLeft , onRight) * ), * 'Ok: 1' * ) - * assert.strictEqual( + * assert.deepStrictEqual( * pipe( * E.left(['error 1', 'error 2']), * E.match(onLeft , onRight) @@ -1080,9 +1080,9 @@ export const contains = (equivalence: Equivalence) => * * const f = E.exists((n: number) => n > 2) * - * assert.strictEqual(f(E.left('a')), false) - * assert.strictEqual(f(E.right(1)), false) - * assert.strictEqual(f(E.right(3)), true) + * assert.deepStrictEqual(f(E.left('a')), false) + * assert.deepStrictEqual(f(E.right(1)), false) + * assert.deepStrictEqual(f(E.right(3)), true) * * @since 1.0.0 */ diff --git a/src/Function.ts b/src/Function.ts index 3b2ca4835..0266cbea2 100644 --- a/src/Function.ts +++ b/src/Function.ts @@ -83,9 +83,17 @@ export const getMonoid = (Monoid: monoid.Monoid) => } /** + * Apply a function to a given value. + * + * @example + * import { pipe, apply } from '@fp-ts/core/Function' + * import { increment } from '@fp-ts/core/Number' + * + * assert.deepStrictEqual(pipe(2, apply(increment)), 3) + * * @since 1.0.0 */ -export const apply = (a: A) => (self: (a: A) => B): B => self(a) +export const apply = (self: (a: A) => B) => (a: A): B => self(a) /** * A lazy argument @@ -166,7 +174,7 @@ export const constVoid: LazyArg = constUndefined * * const f = (a: number) => (b: string) => a - b.length * - * assert.strictEqual(flip(f)('aaa')(2), -1) + * assert.deepStrictEqual(flip(f)('aaa')(2), -1) * * @since 1.0.0 */ @@ -185,7 +193,7 @@ export const flip = , B extends Array, C>( * * const f = flow(len, double) * - * assert.strictEqual(f('aaa'), 6) + * assert.deepStrictEqual(f('aaa'), 6) * * @see {@link pipe} * @since 1.0.0 @@ -316,7 +324,7 @@ export const absurd = (_: never): A => { * * const add = tupled((x: number, y: number): number => x + y) * - * assert.strictEqual(add([1, 2]), 3) + * assert.deepStrictEqual(add([1, 2]), 3) * * @since 1.0.0 */ @@ -341,10 +349,10 @@ export const untupled = , B>(f: (a: A) => B): ( * const double = (n: number): number => n * 2 * * // without pipe - * assert.strictEqual(double(len('aaa')), 6) + * assert.deepStrictEqual(double(len('aaa')), 6) * * // with pipe - * assert.strictEqual(pipe('aaa', len, double), 6) + * assert.deepStrictEqual(pipe('aaa', len, double), 6) * * @see {@link flow} * @since 1.0.0 diff --git a/src/Option.ts b/src/Option.ts index 5262ce0d8..d8f198c47 100644 --- a/src/Option.ts +++ b/src/Option.ts @@ -111,9 +111,9 @@ export const some: (value: A) => Option = option.some * @example * import { some, none, isOption } from '@fp-ts/core/Option' * - * assert.strictEqual(isOption(some(1)), true) - * assert.strictEqual(isOption(none()), true) - * assert.strictEqual(isOption({}), false) + * assert.deepStrictEqual(isOption(some(1)), true) + * assert.deepStrictEqual(isOption(none()), true) + * assert.deepStrictEqual(isOption({}), false) * * @category guards * @since 1.0.0 @@ -128,8 +128,8 @@ export const isOption: (input: unknown) => input is Option = option.isO * @example * import { some, none, isNone } from '@fp-ts/core/Option' * - * assert.strictEqual(isNone(some(1)), false) - * assert.strictEqual(isNone(none()), true) + * assert.deepStrictEqual(isNone(some(1)), false) + * assert.deepStrictEqual(isNone(none()), true) * * @category guards * @since 1.0.0 @@ -144,8 +144,8 @@ export const isNone: (self: Option) => self is None = option.isNone * @example * import { some, none, isSome } from '@fp-ts/core/Option' * - * assert.strictEqual(isSome(some(1)), true) - * assert.strictEqual(isSome(none()), false) + * assert.deepStrictEqual(isSome(some(1)), true) + * assert.deepStrictEqual(isSome(none()), false) * * @category guards * @since 1.0.0 @@ -259,8 +259,8 @@ export const toEither: (onNone: LazyArg) => (self: Option) => Either * import { some, none, getOrElse } from '@fp-ts/core/Option' * import { pipe } from '@fp-ts/core/Function' * - * assert.strictEqual(pipe(some(1), getOrElse(() => 0)), 1) - * assert.strictEqual(pipe(none(), getOrElse(() => 0)), 0) + * assert.deepStrictEqual(pipe(some(1), getOrElse(() => 0)), 1) + * assert.deepStrictEqual(pipe(none(), getOrElse(() => 0)), 0) * * @category error handling * @since 1.0.0 @@ -364,8 +364,8 @@ export const firstSomeOf = (collection: Iterable>): Option => { * import { some, none, getOrNull } from '@fp-ts/core/Option' * import { pipe } from '@fp-ts/core/Function' * - * assert.strictEqual(pipe(some(1), getOrNull), 1) - * assert.strictEqual(pipe(none(), getOrNull), null) + * assert.deepStrictEqual(pipe(some(1), getOrNull), 1) + * assert.deepStrictEqual(pipe(none(), getOrNull), null) * * @category interop * @since 1.0.0 @@ -381,8 +381,8 @@ export const getOrNull: (self: Option) => A | null = getOrElse(constNull) * import { some, none, getOrUndefined } from '@fp-ts/core/Option' * import { pipe } from '@fp-ts/core/Function' * - * assert.strictEqual(pipe(some(1), getOrUndefined), 1) - * assert.strictEqual(pipe(none(), getOrUndefined), undefined) + * assert.deepStrictEqual(pipe(some(1), getOrUndefined), 1) + * assert.deepStrictEqual(pipe(none(), getOrUndefined), undefined) * * @category interop * @since 1.0.0 @@ -1085,7 +1085,7 @@ export const traverseTap: ( * import { some, none, match } from '@fp-ts/core/Option' * import { pipe } from '@fp-ts/core/Function' * - * assert.strictEqual( + * assert.deepStrictEqual( * pipe( * some(1), * match(() => 'a none', a => `a some containing ${a}`) @@ -1093,7 +1093,7 @@ export const traverseTap: ( * 'a some containing 1' * ) * - * assert.strictEqual( + * assert.deepStrictEqual( * pipe( * none(), * match(() => 'a none', a => `a some containing ${a}`) @@ -1191,11 +1191,11 @@ export const flatMapNullable = (f: (a: A) => B | null | undefined) => * import { pipe } from '@fp-ts/core/Function' * * const O = liftOrder(N.Order) - * assert.strictEqual(O.compare(none(), none()), 0) - * assert.strictEqual(O.compare(none(), some(1)), -1) - * assert.strictEqual(O.compare(some(1), none()), 1) - * assert.strictEqual(O.compare(some(1), some(2)), -1) - * assert.strictEqual(O.compare(some(1), some(1)), 0) + * assert.deepStrictEqual(O.compare(none(), none()), 0) + * assert.deepStrictEqual(O.compare(none(), some(1)), -1) + * assert.deepStrictEqual(O.compare(some(1), none()), 1) + * assert.deepStrictEqual(O.compare(some(1), some(2)), -1) + * assert.deepStrictEqual(O.compare(some(1), some(1)), 0) * * @category sorting * @since 1.0.0 @@ -1254,21 +1254,21 @@ export const contains = (equivalence: Equivalence) => * import { some, none, exists } from '@fp-ts/core/Option' * import { pipe } from '@fp-ts/core/Function' * - * assert.strictEqual( + * assert.deepStrictEqual( * pipe( * some(1), * exists(n => n > 0) * ), * true * ) - * assert.strictEqual( + * assert.deepStrictEqual( * pipe( * some(1), * exists(n => n > 1) * ), * false * ) - * assert.strictEqual( + * assert.deepStrictEqual( * pipe( * none(), * exists(n => n > 0) @@ -1295,7 +1295,7 @@ export const exists = (predicate: Predicate) => * import { pipe } from '@fp-ts/core/Function' * * const iterable = [some(1), none(), some(2), none()] - * assert.strictEqual(pipe(iterable, reduceAll(0, (b, a) => b + a)), 3) + * assert.deepStrictEqual(pipe(iterable, reduceAll(0, (b, a) => b + a)), 3) */ export const reduceAll = (b: B, f: (b: B, a: A) => B) => (self: Iterable>): B => { diff --git a/test/Function.ts b/test/Function.ts index a5bcd369a..6a749a6be 100644 --- a/test/Function.ts +++ b/test/Function.ts @@ -1,4 +1,4 @@ -import * as Function from "@fp-ts/core/Function" +import * as _ from "@fp-ts/core/Function" import * as Number from "@fp-ts/core/Number" import * as String from "@fp-ts/core/String" import { deepStrictEqual, double } from "@fp-ts/core/test/util" @@ -9,7 +9,7 @@ const g = double describe.concurrent("Function", () => { it("getSemigroup", () => { - const S = Function.getSemigroup(Number.SemigroupSum)() + const S = _.getSemigroup(Number.SemigroupSum)() const f = (s: string) => s === "a" ? 0 : 1 const g = S.combine(String.length, f) deepStrictEqual(g(""), 1) @@ -19,7 +19,7 @@ describe.concurrent("Function", () => { }) it("getMonoid", () => { - const M = Function.getMonoid(Number.MonoidSum)() + const M = _.getMonoid(Number.MonoidSum)() const f = (s: string) => s === "a" ? 0 : 1 const g = M.combine(String.length, f) deepStrictEqual(g(""), 1) @@ -31,80 +31,80 @@ describe.concurrent("Function", () => { }) it("apply", () => { - deepStrictEqual(Function.apply("a")(String.length), 1) + deepStrictEqual(_.pipe("a", _.apply(String.length)), 1) }) it("flip", () => { const f = (a: number) => (b: string) => a - b.length const g = (a: number, i = 0) => (b: number) => a ** b + i - deepStrictEqual(Function.flip(f)("aaa")(2), -1) - deepStrictEqual(Function.flip(g)(2)(2, 1), 5) + deepStrictEqual(_.flip(f)("aaa")(2), -1) + deepStrictEqual(_.flip(g)(2)(2, 1), 5) }) it("compose", () => { - deepStrictEqual(Function.pipe(String.length, Function.compose(double))("aaa"), 6) + deepStrictEqual(_.pipe(String.length, _.compose(double))("aaa"), 6) }) it("unsafeCoerce", () => { - deepStrictEqual(Function.unsafeCoerce, Function.identity) + deepStrictEqual(_.unsafeCoerce, _.identity) }) it("constant", () => { - deepStrictEqual(Function.constant("a")(), "a") + deepStrictEqual(_.constant("a")(), "a") }) it("constTrue", () => { - deepStrictEqual(Function.constTrue(), true) + deepStrictEqual(_.constTrue(), true) }) it("constFalse", () => { - deepStrictEqual(Function.constFalse(), false) + deepStrictEqual(_.constFalse(), false) }) it("constNull", () => { - deepStrictEqual(Function.constNull(), null) + deepStrictEqual(_.constNull(), null) }) it("constUndefined", () => { - deepStrictEqual(Function.constUndefined(), undefined) + deepStrictEqual(_.constUndefined(), undefined) }) it("constVoid", () => { - deepStrictEqual(Function.constVoid(), undefined) + deepStrictEqual(_.constVoid(), undefined) }) it("absurd", () => { - assert.throws(() => Function.absurd(null as any as never)) + assert.throws(() => _.absurd(null as any as never)) }) it("hole", () => { - assert.throws(() => Function.hole()) + assert.throws(() => _.hole()) }) it("SK", () => { - expect(Function.SK(1, 2)).toEqual(2) + expect(_.SK(1, 2)).toEqual(2) }) it("flow", () => { - deepStrictEqual(Function.flow(f)(2), 3) - deepStrictEqual(Function.flow(f, g)(2), 6) - deepStrictEqual(Function.flow(f, g, f)(2), 7) - deepStrictEqual(Function.flow(f, g, f, g)(2), 14) - deepStrictEqual(Function.flow(f, g, f, g, f)(2), 15) - deepStrictEqual(Function.flow(f, g, f, g, f, g)(2), 30) - deepStrictEqual(Function.flow(f, g, f, g, f, g, f)(2), 31) - deepStrictEqual(Function.flow(f, g, f, g, f, g, f, g)(2), 62) - deepStrictEqual(Function.flow(f, g, f, g, f, g, f, g, f)(2), 63) + deepStrictEqual(_.flow(f)(2), 3) + deepStrictEqual(_.flow(f, g)(2), 6) + deepStrictEqual(_.flow(f, g, f)(2), 7) + deepStrictEqual(_.flow(f, g, f, g)(2), 14) + deepStrictEqual(_.flow(f, g, f, g, f)(2), 15) + deepStrictEqual(_.flow(f, g, f, g, f, g)(2), 30) + deepStrictEqual(_.flow(f, g, f, g, f, g, f)(2), 31) + deepStrictEqual(_.flow(f, g, f, g, f, g, f, g)(2), 62) + deepStrictEqual(_.flow(f, g, f, g, f, g, f, g, f)(2), 63) // this is just to satisfy noImplicitReturns and 100% coverage - deepStrictEqual((Function.flow as any)(...[f, g, f, g, f, g, f, g, f, g]), undefined) + deepStrictEqual((_.flow as any)(...[f, g, f, g, f, g, f, g, f, g]), undefined) }) it("tupled", () => { const f1 = (a: number): number => a * 2 const f2 = (a: number, b: number): number => a + b - const u1 = Function.tupled(f1) - const u2 = Function.tupled(f2) + const u1 = _.tupled(f1) + const u2 = _.tupled(f2) deepStrictEqual(u1([1]), 2) deepStrictEqual(u2([1, 2]), 3) }) @@ -112,45 +112,45 @@ describe.concurrent("Function", () => { it("untupled", () => { const f1 = (a: readonly [number]): number => a[0] * 2 const f2 = (a: readonly [number, number]): number => a[0] + a[1] - const u1 = Function.untupled(f1) - const u2 = Function.untupled(f2) + const u1 = _.untupled(f1) + const u2 = _.untupled(f2) deepStrictEqual(u1(1), 2) deepStrictEqual(u2(1, 2), 3) }) it("pipe", () => { - deepStrictEqual(Function.pipe(2), 2) - deepStrictEqual(Function.pipe(2, f), 3) - deepStrictEqual(Function.pipe(2, f, g), 6) - deepStrictEqual(Function.pipe(2, f, g, f), 7) - deepStrictEqual(Function.pipe(2, f, g, f, g), 14) - deepStrictEqual(Function.pipe(2, f, g, f, g, f), 15) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g), 30) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f), 31) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g), 62) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f), 63) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g), 126) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f), 127) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g), 254) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f), 255) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g), 510) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 511) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g), 1022) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 1023) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g), 2046) - deepStrictEqual(Function.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 2047) + deepStrictEqual(_.pipe(2), 2) + deepStrictEqual(_.pipe(2, f), 3) + deepStrictEqual(_.pipe(2, f, g), 6) + deepStrictEqual(_.pipe(2, f, g, f), 7) + deepStrictEqual(_.pipe(2, f, g, f, g), 14) + deepStrictEqual(_.pipe(2, f, g, f, g, f), 15) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g), 30) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f), 31) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g), 62) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f), 63) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g), 126) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f), 127) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g), 254) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f), 255) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g), 510) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 511) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g), 1022) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 1023) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g), 2046) + deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 2047) deepStrictEqual( - (Function.pipe as any)(...[2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g]), + (_.pipe as any)(...[2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g]), 4094 ) }) it("dual", () => { - const f = Function.dual< + const f = _.dual< (self: number, that: number) => number, (that: number) => (self: number) => number >(2, (a: number, b: number): number => a - b) deepStrictEqual(f(3, 2), 1) - deepStrictEqual(Function.pipe(3, f(2)), 1) + deepStrictEqual(_.pipe(3, f(2)), 1) }) })