From cc8eeeb482f279c80ebef17fc5968e73a51b48b8 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Thu, 6 Nov 2025 21:12:44 -0800 Subject: add examples --- examples/mapper.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/mapper.ts (limited to 'examples/mapper.ts') diff --git a/examples/mapper.ts b/examples/mapper.ts new file mode 100644 index 0000000..3485e02 --- /dev/null +++ b/examples/mapper.ts @@ -0,0 +1,36 @@ +/* +If you've ever said "I wish generic types were first class," you're probably doing something wrong. +On the other hand, you might be doing something right! KaiScript makes this possible. +*/ + +import { CallFn, Evaluate, FnPrim, Lex, Parse } from "../src"; + +// You might have a type that looks like this +type MyGenericMapper = `${T}`; +// And another that looks like this +type MyGenericMapper2 = `number:${T}`; + +// And another type that wants to consume them +//@ts-expect-error +type Map5 = Mapper<5>; + +// Hmm, can't do that. ...maybe this? +type Map5_2() => string> = ReturnType< + //@ts-expect-error + Mapper<5> +>; + +// But with KaiScript: + +type MyKaiScriptMapper = Evaluate>>[0]; +type MyKaiScriptMapper2 = Evaluate< + Parse> +>[0]; + +type Map5KaiScript = CallFn; +// "5" +type Mapped1 = Map5KaiScript; +// "number:5" +type Mapped2 = Map5KaiScript; + +// KaiScript lets you get an extra order of primitivity out of your types -- cgit v1.2.3-70-g09d2