hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
is this a high quality code? import { Maybe, Just, Nothing } from "./Maybe";
type Observer = (thing: T) => void;
type Unsub = () => void;
interface Box { kind: "Box"; set: (f: (thing: T | undefined) => T) => void; unwrap: () => T; ref: () => T; empty: () => boolean; sub: (f: Observer, id?: string) => Unsub; unsub: (id?: string) => void; maybe: () => Maybe; }
const Box = (thunk?: () => T): Box => { const kind = "Box";
let thing = thunk ? new WeakRef(thunk()) : void 0;
let initialized = thing !== undefined;
let observers: Map<string, Observer> | undefined = void 0;
thunk = void 0 as never;
const ref = () => { const r = thing?.deref(); if (r === undefined && initialized) throw new Error("the box is empty"); return r as T; };
- Assistant
- User
is this ok? import { DeepEqual } from "./DeepEqual";
const CACHE = new Map<string, [unknown, unknown[] | undefined]>();
const Memo = (thunk: () => T, id: string, deps?: unknown[]): T => { const cached = CACHE.get(id); if (!cached || (deps && cached[1] && !DeepEqual(cached[1], deps))) { const res = thunk(); CACHE.set(id, [res, deps]); return res; } return cached[0] as T; };
export { Memo };
- Assistant
- User
im using it in my reactive lib. is this ok usage? this is a dev tools widget import { Render, Root, Signal, Reader, IO, Box, Memo } from "../../lib/index"; import { Window } from "./Window"; import { Console } from "./Console"; import { Tools } from "./Tools";
interface Settings { mode: "console" | "tools"; }
const defaultSettings: Settings = { mode: "console" };
const loadSettings = Reader( (id: string) => ({ mode: localStorage.getItem(
${id}: mode) ?? "console", }) as Settings, );const saveSettings = IO((id: string, mode: Signal<"console" | "tools">) => { document.addEventListener("visibilitychange", () => localStorage.setItem(
${id}: mode, mode.ref()), ); });const initConsole = Reader((logs: any[]) => { console.log = (...things: any[]) => things.forEach((x) => logs.push(x)); });
const InitTools = (id: string): void => { const settings = loadSettings.ex(id).alt(defaultSettings); const mode = Signal(settings.mode); const logs: any[] = [];
initConsole.ex(logs); saveSettings.ex(id, mode);
Root(document.body, () => Render(() => { if (mode.ref() === "tools") initConsole.ex(logs); return Window({ id: id + "window", mode: mode, slot: () => mode.ref() === "console" ? Memo(() => Console({ logs }), id + "console", [logs]) : Tools({}), }); }, [mode]), ); };
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.