This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type CapKebabCase<S extends string> = S extends `${infer A}-${infer B}` ? `${Capitalize<A>}-${CapKebabCase<B>}` : Capitalize<S>; | |
declare function test<S extends string>(s: S & CapKebabCase<S>): void | |
test("hello-there") | |
test("Hello-there") | |
test("Hello-There") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script type="importmap"> | |
{ | |
"imports": { | |
"moduleA": "/moduleA.js", | |
"moduleB": "/moduleB.js", | |
"react": "https://esm.sh/react@17" | |
}, | |
"scopes": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ArgsToFunc<Args extends [...any]> = Args extends [infer LastArg, infer Result] | |
? (a: LastArg) => Result //last argument case | |
: Args extends [infer Arg, ...infer Args, infer Result] // n-1 argument case | |
? (a: Arg) => ArgsToFunc<[...Args, Result]> | |
: never //Args was not a 2tuple, abort | |
function curry<F extends (...args: any) => any>(fn: F): ArgsToFunc<[...Parameters<F>, ReturnType<F>]> { | |
return null as any; //todo - I'm just playing at the type level | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Action = { type: string }; | |
export type Reducer<S, A extends Action> = (state: S, action: A) => S; | |
export type ReducerByAction<S, A extends Action> = A extends any | |
? Partial<Record<A["type"], Reducer<S, A>>> | |
: never; | |
export type ReducerByKey<S, A extends Action> = Partial<{ | |
[SK in keyof S]: Reducer<S[SK], A> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { hole, identity, pipe } from "@effect-ts/core/Function"; | |
/** Redux Types */ | |
/** Redux Types */ | |
/** Redux Types */ | |
type Reducer<S, A> = (s: S, a: A) => S; | |
type Store<S, A> = { | |
get: () => S; | |
dispatch: (a: A) => void; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function identity<T>(t:T):T{return t}; | |
class NumExpr<A> { | |
readonly _tag = "num"; | |
constructor (readonly value: number, readonly proof: (v: number) => A) {} | |
} | |
class StringExpr<A> { | |
readonly _tag = "str" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Comonad2C } from 'fp-ts/lib/Comonad'; | |
import { pipe } from 'fp-ts/lib/function'; | |
import { FunctionN } from 'fp-ts/lib/function'; | |
import { Monoid } from 'fp-ts/lib/Monoid'; | |
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; | |
import { pipeable } from 'fp-ts/lib/pipeable'; | |
/** | |
* OOP style builder pattern but in FP | |
* References: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Batching { | |
updateRequested = false; | |
async scheduleUpdate(id: number) { | |
if (!this.updateRequested) { | |
this.updateRequested = true; | |
this.updateRequested = await false; | |
this.update(id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Impl | |
*/ | |
type TransitionHandler< | |
From extends Union, | |
States extends From, | |
Event extends Union | |
> = (from: From, event: Event) => States; | |
type Transition< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; | |
type Union<T extends string> = Record<T, string>; | |
type MatchHandlers<T extends string, P extends Union<T>, R> = P extends any ? Record<P[T], (p: P) => R> : never; | |
type DefaultedOrFullHandlers<T extends string, P extends Union<T>, R> = | |
| (Partial<MatchHandlers<T, P, R>> & { otherwise: () => R }) | |
| UnionToIntersection<MatchHandlers<T, P, R>>; | |
/** | |
* Create a match function based on the given tag property. |
NewerOlder