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 { Falsy, filter, type OperatorFunction } from 'rxjs'; | |
type FalsyTypesOf<T> = T extends Falsy ? T : never; | |
export function filterIsFalsy<T>(): OperatorFunction<T, FalsyTypesOf<T>> { | |
return source$ => source$.pipe(filter<FalsyTypesOf<T>>(value => !value)); | |
} |
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
// Represents an observer that listens to data emitted by the observable. | |
type Observer<T> = { | |
next: (value: T) => void; // Handler for each emitted value | |
error: (error: unknown) => void; // Handler for any error that occurs | |
complete: () => void; // Handler for the completion of the observable sequence | |
}; | |
// Represents an ongoing subscription to an observable. Provides a mechanism to release resources or cancel emission. | |
type Subscription = { | |
unsubscribe: () => void; |
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 enum E_PromiseState { | |
PENDING = 'pending', | |
FULFILLED = 'fulfilled', | |
REJECTED = 'rejected', | |
} |
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 ListNode { | |
constructor(public value: any, public next: ListNode | null) {} | |
} | |
function revLinkList(head: ListNode | null) { | |
let currentNode = head; | |
let prev = null; | |
while (currentNode) { | |
let next = currentNode.next; | |
currentNode.next = prev; |
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 trampoline(fn) { | |
return (...args) => { | |
let result = fn(...args); | |
while (typeof result === 'function') { | |
result = result(); | |
} | |
return result; | |
}; | |
} |
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 T_UnaryFunction<I, O> = (x: I) => O; | |
type T_Fn<I, O> = { | |
run: T_UnaryFunction<I, O>; | |
chain: <P>(f: T_UnaryFunction<O, T_Fn<I, P>>) => T_Fn<I, P>; | |
map: <A>(f: T_UnaryFunction<O, A>) => T_Fn<I, A>; | |
}; | |
const Fn = <I, O = I>(run: T_UnaryFunction<I, O>): T_Fn<I, O> => ({ | |
run, | |
chain: <P>(f: T_UnaryFunction<O, T_Fn<I, P>>) => Fn((x) => f(run(x)).run(x)), |
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
// Definitions | |
// ==================== | |
const Right = (x) => ({ | |
chain: (f) => f(x), | |
map: (f) => Right(f(x)), | |
fold: (f, g) => g(x), | |
toString: () => `Right(${x})` | |
}); | |
const Left = (x) => ({ |
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 { compose, head, toLower } from 'ramda'; | |
function trampoline(fn: Function) { | |
return function trampolined(...args: any[]) { | |
let result = fn(...args); | |
while (typeof result === 'function') { | |
result = result(); | |
} |
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
// types | |
type T_XF<XF_Before, XF_After> = (a: XF_Before) => XF_After; | |
type T_Pred<Pred_Fn> = (fn: Pred_Fn) => boolean; | |
type T_Reducer<Before, After> = (acc: After, cur: Before) => After; | |
type T_Hor<Inner_Before, Before, After> = ( | |
reducer: T_Reducer<Before, After> | |
) => T_Reducer<Inner_Before, After>; |
NewerOlder