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 { Preconditions } from 'base/preconditions'; | |
import { flushPromises } from 'base/testing/flush_promises'; | |
import { runTasksWithRateLimit, Task } from '../run_tasks_with_rate_limit'; | |
type Resolve<T> = (value?: T | PromiseLike<T>) => void; | |
type Reject = (reason: any) => void; | |
type Deferred<T = void> = Promise<T> & { resolve: Resolve<T>; reject: Reject }; | |
const deferred = <T>(): Deferred<T> => { |
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 { DoublyLinkedList, ListNode, LRUCache } from '../lru_cache'; | |
describe('DoublyLinkedList', () => { | |
test('keys', () => { | |
const dll = new DoublyLinkedList<string, number>(); | |
const head: ListNode<string, number> = { | |
key: 'one', | |
value: 0, | |
prev: undefined, |
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
function pick<T, K extends keyof T>(k: K): (t: T) => T[K] { | |
return (t: T) => t[k]; | |
} |
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
type UnaryFunction<A, B> = (arg: A) => B | |
function pipe<T, A, B, C, D, E, F>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>): UnaryFunction<T, F>; | |
function pipe<T, R>(...operations: UnaryFunction<any, any>[]): UnaryFunction<T, R> { | |
return initial => operations.reduce((prev, nextFn) => nextFn(prev), initial) | |
} | |
const curry2 = <A, B, C>(fn: (a: A, b: B) => C) => (a: A) => (b: B) => fn(a, b) | |
const filter = curry2(<T>(fn: UnaryFunction<T, boolean>, arr: T[]) => arr.filter(fn)) |
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 { Preconditions, UnreachableError } from 'base/preconditions'; | |
export module FormFieldValue { | |
export const enum Type { | |
Text, | |
Select, | |
OnOff, | |
Numeric, | |
} |
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 module Maybe { | |
enum Variant { | |
Just = 1, | |
Nothing, | |
} | |
export type Nothing = Readonly<{ type: Variant.Nothing }>; | |
export type Just<T> = Readonly<{ type: Variant.Just; value: T }>; |
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
function fzf-checkout | |
git checkout (git branch | rg '^\s*[^*]' | fzf | sed 's/^ *//;s/ *$//') | |
end |
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
const NO_ARGUMENTS_YET = Symbol("no arguments yet"); | |
function allEqual<Arr extends any[]>(first: Arr, second: Arr): boolean { | |
return first.every((value, i) => value === second[i]); | |
} | |
export function memoizeOnce<ArgsT extends any[], ReturnT>( | |
fn: (...args: ArgsT) => ReturnT, | |
comparator: (prevArgs: ArgsT, nextArgs: ArgsT) => boolean = allEqual | |
) { |
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 function bufferStream( | |
handler: (events: Event[]) => void, | |
timeMs: number, | |
): (event: Event) => void { | |
let timeout: number = null; | |
let events: Event[] = []; | |
return (event: Event) => { | |
if (timeout != null) { | |
clearTimeout(timeout); | |
} |
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
type OptionalProperty<T, P extends keyof T> = { | |
[K in Exclude<keyof T, P>]: T[K]; | |
} & { | |
[K in Extract<keyof T, P>]?: T[K]; | |
}; | |
// Example | |
type Person = { age: number; name: string; country: string; }; | |