//#region src/types/index.d.ts type Type = unknown; //#endregion //#region src/foldable/Foldable.d.ts /** * Foldable type class represents data structures that can be folded to a summary value. * * This interface provides the universal fold operations (foldLeft, foldRight) that work * consistently across all data structures. The `fold` method is intentionally excluded * because it has different semantics for sum types vs collections: * - Sum types (Option, Either, Try): `fold(onEmpty, onValue)` — pattern match * - Collections (List, Set, Map): `fold(initial, fn)` — left-reduce accumulator * * Each type category defines its own `fold` with the appropriate signature. * * @typeParam A - The type of elements in the data structure */ interface Foldable { /** * Left-associative fold using the provided zero value and operation * @param z - Zero/identity value * @returns A function that takes an operation to apply */ foldLeft(z: B): (op: (b: B, a: A) => B) => B; /** * Right-associative fold using the provided zero value and operation * @param z - Zero/identity value * @returns A function that takes an operation to apply */ foldRight(z: B): (op: (a: A, b: B) => B) => B; } //#endregion //#region src/pipe/index.d.ts /** * Pipe interface for functional data structures * @typeParam T - The type of value to pipe */ interface Pipe { /** * Pipes the value through the provided function * @param f - The function to apply to the value * @returns The result of applying the function to the value * @typeParam U - The return type of the function */ pipe(f: (value: T) => U): U; } //#endregion //#region src/serializable/Serializable.d.ts /** * Methods for different serialization formats */ interface SerializationMethods { toJSON(): string; toYAML(): string; toBinary(): string; } /** * Shape of the envelope object emitted by a Serializable's instance-level * `toJSON()` (the method native `JSON.stringify` picks up via protocol). * Concrete types narrow this with their specific marker/tag literals. * * The `@functype` marker is the type discriminator (defends against * `_tag`-collision with Effect/fp-ts). `_tag` is the variant discriminator * within that type — kept across the board (variant-less types repeat the * marker for back-compat with 1.1.0 readers that did `parsed._tag === "List"`). * * Payload shape is type-specific: canonical types carry `value`; failure * branches (`Try.Failure`, `Task.Err`, `Lazy` with thrown thunk) carry * `error: SerializedError` instead. */ interface SerializableEnvelope { readonly "@functype": string; readonly _tag: string; readonly [key: string]: unknown; } interface Serializable { serialize(): SerializationMethods; /** * Custom JSON serialization. Returns the canonical `@functype`-marked * envelope object so native `JSON.stringify` (and the rest of the JSON * `toJSON` protocol) emits a round-trip-able shape that * `Serialization.deserialize` can reconstruct. * * Added in 1.2.0. Concrete types narrow the return to their specific * marker/tag literals. */ toJSON(): SerializableEnvelope; } //#endregion //#region src/typeable/Typeable.d.ts /** * Base interface for objects with a type tag * @internal */ interface TypeableBase { readonly _tag: Tag; } type Typeable = T & TypeableBase; /** * Parameters for creating a Typeable instance * @internal */ type TypeableParams = { _tag: Tag; impl: T; }; /** * Utility type to extract the Tag from a Typeable type * @typeParam T - The Typeable type to extract the tag from * @internal */ type ExtractTag = T extends Typeable ? Tag : never; /** * Core utility for creating nominal typing in TypeScript by adding a type tag to any object. * This allows for creating distinct types that are structurally identical but considered different by TypeScript's type system. * * @param params - The parameters containing the tag and implementation * @returns A Typeable object with the specified tag * @typeParam Tag - The string literal type used as the discriminator * @typeParam T - The base type to extend with the tag */ declare function Typeable({ _tag, impl }: TypeableParams): Typeable; /** * Type guard with automatic type inference using the full type * @param value - The value to check * @param tag - The tag to check for * @returns Whether the value is a Typeable with the specified tag */ declare function isTypeable(value: unknown, tag: string): value is T; //#endregion //#region src/tuple/Tuple.d.ts interface Tuple extends Foldable, Pipe>, Serializable>, Typeable<"Tuple"> { readonly [Symbol.toStringTag]: string; get(index: K): T[K]; fold(initial: B, fn: (acc: B, a: T[number]) => B): B; map(f: (value: T) => U): Tuple; flatMap(f: (value: T) => Tuple): Tuple; toArray(): T; length: number; [Symbol.iterator](): Iterator; toString(): string; toValue(): { _tag: "Tuple"; value: T; }; } /** * Tuple provides a type-safe, fixed-length array with functional operations. * * @example * // Creating tuples * const t1 = Tuple([1, "hello", true]) * const t2 = Tuple.of(1, "hello", true) * const pair = Tuple.pair("key", 42) * * @example * // Type-safe access * const triple = Tuple.triple("x", 10, true) * const first = triple.get(0) // string * const second = triple.get(1) // number * const third = triple.get(2) // boolean * * @example * // Functional operations * const doubled = Tuple([1, 2, 3]) * .map(arr => arr.map(x => x * 2)) * .toArray() // [2, 4, 6] */ declare const Tuple: ((values: T) => Tuple) & { /** * Create a Tuple from multiple arguments * @example * const t = Tuple.of(1, "hello", true) * // TypeScript infers: Tuple<[number, string, boolean]> */ of: (...values: T) => Tuple; /** * Create a Tuple of size 2 (pair) * @example * const pair = Tuple.pair("key", 42) * // TypeScript infers: Tuple<[string, number]> */ pair: (first: A, second: B) => Tuple<[A, B]>; /** * Create a Tuple of size 3 (triple) * @example * const triple = Tuple.triple("x", 10, true) * // TypeScript infers: Tuple<[string, number, boolean]> */ triple: (first: A, second: B, third: C) => Tuple<[A, B, C]>; /** * Create an empty Tuple * @example * const empty = Tuple.empty() * // TypeScript infers: Tuple<[]> */ empty: () => Tuple<[]>; /** * Create a Tuple from an array (alias for constructor) * @example * const t = Tuple.from([1, 2, 3]) */ from: (values: T) => Tuple; /** * Reconstruct a Tuple from a JSON envelope emitted by `serialize().toJSON()` * or instance `toJSON()`. Verifies `@functype === "Tuple"` if the marker is * present (the marker became canonical in 1.2.0; older envelopes are * accepted by leniently treating missing-marker as opt-in legacy). */ fromJSON: (json: string) => Tuple; }; //#endregion export { isTypeable as a, SerializationMethods as c, Type as d, TypeableParams as i, Pipe as l, ExtractTag as n, Serializable as o, Typeable as r, SerializableEnvelope as s, Tuple as t, Foldable as u };