Skip to content

Commit

Permalink
add a 'test' file for CPS.chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordfirespeed committed Aug 24, 2024
1 parent 1660056 commit 3ce3b68
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions type-test/chain.ts
Original file line number Diff line number Diff line change
@@ -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) }
)

0 comments on commit 3ce3b68

Please sign in to comment.