This file contains hidden or 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 { withAbortableResolvers } from "./with-abortable-resolvers"; | |
export function sleep(ms: number, signal?: AbortSignal): Promise<void> { | |
const { promise, resolve } = withAbortableResolvers<void>(signal); | |
const handle = setTimeout(resolve, ms); | |
return promise.finally(() => clearTimeout(handle)); | |
} |
This file contains hidden or 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 class SparseSetIndexOutOfRangeError extends Error { | |
constructor(message, index, capacity) { | |
super(message); | |
this.index = index; | |
this.capacity = capacity; | |
} | |
} | |
export class SparseSetUnsafe { | |
constructor(capacity) { |
This file contains hidden or 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 * as Maybe from "./maybe"; | |
import { caseOf } from "./one-of"; | |
const square = (n: number) => n * n; | |
// serializable as plain js arrays | |
console.log(Maybe.of(42)); // [ 'Just', 42 ] | |
// supports exhaustive pattern matching | |
caseOf(Maybe.map(Maybe.of(3), square), { |
This file contains hidden or 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> | |
<head> | |
<style> | |
body { width: 100%; } | |
table { margin: auto; border-spacing: 1rem; } | |
button { padding: 1rem; } | |
</style> | |
</head> | |
<body> | |
<table> |
This file contains hidden or 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
/** | |
* Copyright (c) 2022 Chris Baker | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to | |
* deal in the Software without restriction, including without limitation the | |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
* sell copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* |
This file contains hidden or 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
/** | |
* Copyright (c) 2025 Chris Baker <mail.chris.baker@gmail.com> | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to | |
* deal in the Software without restriction, including without limitation the | |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
* sell copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* |
This file contains hidden or 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
/** | |
* Copyright (c) 2022 Chris Baker | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to | |
* deal in the Software without restriction, including without limitation the | |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
* sell copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* |
This file contains hidden or 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 class Person { | |
private _designation: string; | |
private _first: string; | |
private _last: string; | |
static create(): FluentPerson { | |
return new Person(); | |
} | |
private constructor() { |
This file contains hidden or 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 KeysOfParams<S extends string> = | |
S extends `${infer Before} :${infer Name} ${infer After}` | |
? KeysOfParams<Before> | Name | KeysOfParams<After> | |
: S extends `:${infer Name} ${infer After}` | |
? Name | KeysOfParams<After> | |
: S extends `${infer Before} :${infer Name}` | |
? KeysOfParams<Before> | Name | |
: S extends `:${infer Name}` | |
? Name | |
: never; |
This file contains hidden or 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 class Statistics { | |
private static ensureNotEmpty(arr: readonly number[]): void { | |
if (arr.length === 0) { | |
throw new Error("The array must not be empty."); | |
} | |
} | |
static asc(a: number, b: number): number { | |
return a - b; | |
} |
NewerOlder