Skip to content

Instantly share code, notes, and snippets.

@tcodes0
Last active February 7, 2024 16:07
Show Gist options
  • Save tcodes0/fcd1fac083a9c7f792c70fb49a71177c to your computer and use it in GitHub Desktop.
Save tcodes0/fcd1fac083a9c7f792c70fb49a71177c to your computer and use it in GitHub Desktop.
LINKS AND COOL HACKS
@tcodes0
Copy link
Author

tcodes0 commented Jul 30, 2023

/**
 * Maybe captures the result of some operation that may fail.
 * If there is an non null error, attempting to retrieve result will throw.
 */
export class Maybe<T> {
    #result: T | null
    #error: Error | null

    // constructor(data: Data | null, error: Error | null) {
    constructor() {
        this.#result = null
        this.#error = null
    }

    /**
     * throws unless error() returns null.
     */
    result(): T {
        if (this.#error) {
            throw this.#error
        }

        if (this.#result === null) {
            throw new Error("null data")
        }

        return this.#result
    }

    /**
     * if null, result() is safe to call
     */
    error() {
        return this.#error
    }

    /**
     * error must be null for result to be read
     */
    setResult(data: T) {
        this.#result = data
    }

    /**
     * blocks result from being read
     */
    setError(message: string) {
        this.#error = new Error(message)
    }
}

@tcodes0
Copy link
Author

tcodes0 commented Aug 24, 2023

AI

52.7k words on member-server codebase
244 non mock non test files
find . -type f -name *.go | grep -Ev test.go | grep -Ev mock
avg 314 words per file (handlers)
avg 215 word per file (codebase)
say 5k words for a massive conversation context with ai
have 59k words of context to use with ai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment