From 3ce3b68473acd7f38a3e8b9a5e55d80c24c5616e Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Sat, 24 Aug 2024 18:46:43 +0100 Subject: [PATCH] add a 'test' file for `CPS.chain` --- type-test/chain.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 type-test/chain.ts diff --git a/type-test/chain.ts b/type-test/chain.ts new file mode 100644 index 0000000..34c322d --- /dev/null +++ b/type-test/chain.ts @@ -0,0 +1,35 @@ +import { CPS, type CPSFn } from "../index" + +const cpsFn: CPSFn<[ + (a: number, b: number) => void, + (a: number, b: string) => void, +]> = (cb1, cb2) => { cb1(2,3); cb2(7, "bar") } + +const f1 = (x: number, y: number): CPSFn<[ + (x: number, y?: string) => void, + (x: number) => void, +]> => (cb1, cb2) => { cb1(x+y); cb2(x-y) } + +const f2 = (x: number, y: string): CPSFn<[ + (x: number, y?: string) => void, +]> => (cb1) => { cb1(x, y) } + +const chainOneWay = CPS(cpsFn).chain(f1, f2) + +const chainSecondWay = CPS(cpsFn).chain<[ + (x: number, y?: string) => void, + (x: number) => void, +]>( + (x, y) => (cb1, cb2) => { cb1(x+y); cb2(x-y) }, + (x, y) => (cb1) => { cb1(x, y) } +) + +const chainThirdWay = CPS(cpsFn).chain( + (x: number, y: number) => ( + cb1: (x: number, y?: string) => void, + cb2: (x: number) => void + ) => { cb1(x+y); cb2(x-y) }, + (x: number, y: string) => ( + cb1: (x: number, y?: string) => void, + ) => { cb1(x, y) } +)