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 { arg0, Call, Constant, Eval, Fn, Objects, Tuples } from "../src/index"; | |
type Ok<A> = { tag: "Ok"; value: A }; | |
type Err<B> = { tag: "Err"; value: B }; | |
type Result<A, B> = Ok<A> | Err<B>; | |
type ParseError<expected = unknown, encountered = unknown> = { | |
expected: expected; |
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 MergeParameters3<T extends readonly UnknownFunction[]> = H.Pipe< | |
T, | |
[ | |
H.Let<"parametersList", H.Tuples.Map<H.Functions.Parameters>>, | |
H.Let< | |
"longestLength", | |
H.ComposeLeft< | |
[ | |
H.Get<"parametersList">, | |
H.Tuples.Map<H.Tuples.Length>, |
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
// a conditional type is just type-level code branching | |
// A extends B means "A is assignable to B" | |
type Test1 = "hello" extends string ? true : false; | |
// ^? | |
type Test2 = 2 extends string ? true : false; | |
// ^? |
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 type { Equal, Expect } from '@type-challenges/utils' | |
type Assign<A, B> = { | |
[K in keyof A | keyof B]: K extends keyof B | |
? B[K] | |
: K extends keyof A | |
? A[K] | |
: never; | |
} |
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 Range<n, range extends any[] = []> = | |
range['length'] extends n ? range : Range<n, [...range, range['length']]> | |
type Drop1<a extends any[]> = | |
a extends [...infer inits, any] ? inits : [] | |
type Concat<a extends any[], b extends any[]> = [...a, ...b] | |
type Plus<a, b> = | |
[...Range<a>, ...Range<b>]['length'] |
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
// mapped type version | |
type Fn<T> = { | |
[K in keyof T]: [K, T[K]] /* arbitrary fn using K and T[k] */; | |
}; | |
// distributive union version | |
type Fn2<T> = FromEntries< | |
keyof T extends infer K | |
? K extends keyof T | |
? [K, [K, T[K]] /* arbitrary fn using K and T[k] */] |
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 Option<T> = | |
| { readonly type: 'some'; readonly value: T } | |
| { readonly type: 'none' }; | |
export const none: Option<never> = { type: 'none' }; | |
export const some = <T>(value: T): Option<T> => ({ type: 'some', value }); | |
const compose = |
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
/** | |
* We call "variance" the direction of assignability between two types | |
* (in other words, which type is a subtype of the other). | |
* | |
* The same type can have a different variance in function of his position | |
* in a larger type, and this is what makes assignability in TypeScript | |
* not always straightforwards. | |
* | |
* There are 4 kinds of variance: | |
* - Covariant: if the type `a` is assignable to `a | b`. |
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 TupleToList<xs> = xs extends [infer head, ...(infer tail)] | |
? [head extends any[] ? head[number] : never, ...TupleToList<tail>] | |
: []; | |
function permute<xs extends [] | [any[], ...any[][]]>([ | |
head, | |
...rest | |
]: xs): TupleToList<xs>[]; |
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
const fs = require("fs"); | |
const tasks = JSON.parse(fs.readFileSync("./input-5req-2render-slow.json")); | |
// Build histogram of tasks with buckets of 1000ms | |
const histogram = tasks.reduce((acc, task) => { | |
const key = Math.floor(task.start / 1000) + ""; | |
return Object.assign(acc, { | |
[key]: (acc[key] ?? []).concat(task), | |
}); |