Skip to content

Commit

Permalink
feat: support for union inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
susisu committed Aug 26, 2023
1 parent 8e89e8a commit ca688dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/__tests__/vm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ type Program_1 = ">,[>,]<[.<]";
type Input_1 = "Hello, world!";
type Output_1 = Brainfuck<Program_1, Input_1>;
export type Test_Brainfuck_1 = Assert<Equal<Output_1, "!dlrow ,olleH">>;

type Program_2 = ",[.,]" | ">,[>,]<[.<]";
type Input_2 = "Hello, world!" | "Bye";
type Output_2 = Brainfuck<Program_2, Input_2>;
export type Test_Brainfuck_2 = Assert<
Equal<Output_2, "Hello, world!" | "!dlrow ,olleH" | "Bye" | "eyB">
>;
6 changes: 5 additions & 1 deletion src/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ type RunSub<S> = S extends State<infer P, infer _M, infer _I, infer O, infer R,
/**
* `Brainfuck<P, I>` runs a program `P` with an input `I`.
*/
export type Brainfuck<P extends string, I extends string = ""> = Run<Init<P, I>>;
export type Brainfuck<P extends string, I extends string = ""> = P extends unknown
? I extends unknown
? Run<Init<P, I>>
: never
: never;

0 comments on commit ca688dd

Please sign in to comment.