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 ReadableStreamAsyncIteratorPrototype = Object.create(AsyncIteratorPrototype, { | |
stream: { | |
get() { | |
return this[kStream]; | |
}, | |
enumerable: true, | |
configurable: true | |
}, | |
next: { |
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 ticker = interval(1000).pipe(take(100)); | |
function snooze(ms) { | |
return new Promise(resolve => setTimeout(snooze, ms)); | |
} | |
async function* values() { | |
for await (const number of ticker) { | |
await snooze(2000); | |
yield number; |
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 ConstNumber { | |
#privateNumber: number; | |
#dfbsdfbv =4235; | |
showCallback: (value: number) => void; | |
constructor(privateNumber: number, showCallback: (value: number) => void) { | |
this.#privateNumber = privateNumber; | |
this.showCallback = showCallback; | |
} |
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 ActionsTypesExample = "INIT" | "SYNC" | "LOG_IN" | "LOG_IN_SUCCESS" | "LOG_OUT" | |
type SafeKeyValueMapExample<KS extends keyof any> = { | |
readonly [K in KS]: K; | |
}; | |
const ACTIONS_TYPES_MAP_EXAMPLE: SafeKeyValueMapExample<ActionsTypesExample> = { | |
INIT: "INIT", | |
SYNC: "SYNC", | |
LOG_IN: "LOG_IN", |
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
// https://gal.hagever.com/posts/typing-the-technical-interview-in-typescript/ | |
type Eq<A, B extends A> = "passes"; // B <= A | |
// type test_eq = [ | |
// Eq<"Hello", "Hello">, // passes | |
// Eq<"Hello", "world"> // fails with "'world' does not satisfy constraint 'Hello'" | |
// ]; | |
type NAN = "invalid number"; // we don't support negative numbers |
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 interface Message { | |
status: string; | |
query: string; | |
step: string; | |
richResponse: boolean; | |
payload: Types extends (any) ? Payload<Types> : never; | |
sessionId?: number; | |
} | |
type Types = 'text' | 'date' | 'articles' | 'params'; |
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 Point = (x = 0, y = 0) => ({ | |
setCartesianCoordinates(_x, _y) { | |
x = _x; y = _y; | |
}, | |
setPolarCoordinates(radius, angle) { | |
x = radius * Math.cos(angle); | |
y = radius * Math.sin(angle); | |
}, | |
getCartesianCoordinates() { | |
return { x, y } |
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 IO = (function(io) { | |
io.return = x => () => x; | |
io.unit = io.return; | |
io.of = io.return; | |
io.bind = a => fa => () => fa(a())(); | |
io.flatten = aa => io.bind(aa)(a => io.bind(a)(ar => io.return(ar))); | |
io.join = io.flatten | |
io.takeLeft = a => b => io.bind(a)(ar => io.bind(b)(_ => io.return(ar))); | |
io.takeRight = a => b => io.bind(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
data Expr = Val Int | Add Expr Expr | Mul Expr Expr deriving (Show) | |
data Op = EVALA Expr | ADD Int | EVALM Expr | MUL Int | |
type Cont = [Op] | |
eval :: Expr -> Cont -> Int | |
eval (Val n) c = exec c n | |
eval (Add e f) c = eval e (EVALA f : c) | |
eval (Mul e f) c = eval e (EVALM f : c) |
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 isObject(entity) { | |
return typeof entity === "object" && entity !== null; | |
} | |
function cloneNonObjectProperties(obj) { | |
return Object.fromEntries( | |
Object.entries(obj).filter(([, v]) => !isObject(v)) | |
) | |
} |