Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

工业聚 Lucifier129

🎯
Focusing
View GitHub Profile
View one-shot-algebraic-effects.js
const log = (message) => {
return {
__typename: 'log',
message,
};
};
const raise = (message) => {
return {
__typename: 'exception',
View interpreter-pattern-for-list-process.ts
function pipe<T, A>(a: T[], a1: ListAction<T, A>): A[];
function pipe<T, A, B>(a: T[], a1: ListAction<T, A>, a2: ListAction<A, B>): B[];
function pipe<T, A, B, C>(
a: T[],
a1: ListAction<T, A>,
a2: ListAction<A, B>,
a3: ListAction<B, C>
): C[];
View template-string-type-for-html.ts
type ParseResult = {
success: boolean,
data: any,
source: string
}
type ParseFailed = {
suceess: false,
data: any,
source: string
View template-string-type-for-path.ts
type ToTS<T extends string> =
T extends 'Int'
? number
: T extends 'String'
? string
: T extends 'Bool'
? boolean
: never
View template-string-type-for-graphql.ts
type GraphQLObject<T extends string> =
T extends `\ntype ${infer TypeName} {\n${infer Fields}}\n`
? {
name: TypeName,
fields: {
[key in keyof GraphQLObjectFields<Fields>]: GraphQLObjectFields<Fields>[key]
}
}
: never
View flattenChildren.ts
type NullElement = null | undefined;
type BasicElement = number | boolean | string;
type ArrayElement = Array<VElement>;
type ObjectElement = {
props: {
children?: ArrayElement;
};
View composable-ui.ts
export type Renderable = {
renderable: true;
};
type RenderableVStack = {
elems: Renderable[];
} & Renderable;
const VStack = (...elems: Renderable[]): RenderableVStack => {
return {
View non-empty-selector.ts
type PickKey<T extends Pick<any, any>> = T extends Pick<any, infer K> ? K : never;
type EmptySelector<T extends object = any> = {
select: <K extends keyof T>(key: K) => NoneEmptySelector<T, Pick<T, K>>;
selectAll: () => CompletedSelector<T>;
};
type NoneEmptySelector<T extends object = any, P extends Pick<T, any> = any> = {
selected: P;
select: <K extends Exclude<keyof T, PickKey<P>>>(key: K) => NoneEmptySelector<T, P & Pick<T, K>>;
View procedural-abstraction.ts
// data version
type DraftPost = {
kind: 'DraftPost';
content: string;
};
type ReviewingPost = {
kind: 'ReviewingPost';
content: string;
View project-level-fetch-api.js
export const fetch = (url, options = {}) => {
let { fetch = globalThis.fetch, ...restOptions } = options;
if (typeof fetch !== 'function') {
throw new Error(`Expected fetch to be a function, but received ${fetch}`);
}
let finalUrl = url;
let finalOptions = {
You can’t perform that action at this time.