import { Enum } from './enum'; import { Option } from './option'; /** * Interface for pattern matching on ControlFlow * @template B Type of the break value * @template C Type of the continue value * @template R Return type of the match operation */ interface MatchControlFlow { /** * Handler for Continue variant * @param value The continue value */ Continue: (value?: C) => R; /** * Handler for Break variant * @param value The break value */ Break: (value: B) => R; } /** * ControlFlow represents a flow control state that can either continue (Continue) * or break with a value (Break). * * Key features: * - Type-safe control flow * - Pattern matching support * - Rich set of helper methods * * @template B The type of the break value * @template C The type of the continue value * * @example * ```typescript * function findFirst(iter: Iterable, pred: (x: T) => boolean): Option { * for (const x of iter) { * if (pred(x)) { * return Break(x); * } * } * return Continue(); * } * ``` */ export declare class ControlFlow extends Enum { static Continue(value?: C): ControlFlow; static Break(value: B): ControlFlow; /** * Pattern matches on the ControlFlow * @param patterns Object containing handlers for Continue and Break cases * @returns Result of the matched handler * * @example * ```typescript * const flow = Continue(42); * const result = flow.match({ * Continue: (val) => `Continuing with ${val}`, * Break: (val) => `Breaking with ${val}`, * }); * ``` */ match(patterns: Partial>): R; /** * Returns true if this is a Break variant */ isBreak(): boolean; /** * Returns true if this is a Continue variant */ isContinue(): boolean; /** * Returns the Break value if this is Break, throws otherwise * @throws Error if this is not a Break variant */ breakValue(): Option; /** * Returns the Continue value if this is Continue, throws otherwise * @throws Error if this is not a Continue variant */ continueValue(): Option; /** * Maps the Break value using the provided function * @param fn Function to transform the Break value * @returns New ControlFlow with mapped Break value * * @example * ```typescript * const flow = Break(42); * const mapped = flow.mapBreak(x => x.toString()); // Break("42") * ``` */ mapBreak(fn: (val: B) => U): ControlFlow; /** * Maps the Continue value using the provided function * @param fn Function to transform the Continue value * @returns New ControlFlow with mapped Continue value * * @example * ```typescript * const flow = Continue(42); * const mapped = flow.mapContinue(x => x.toString()); // Continue("42") * ``` */ mapContinue(fn: (val?: C) => U): ControlFlow; } /** * Creates a Continue variant of ControlFlow * @param value Optional continue value */ export declare function Continue(value?: C): ControlFlow; /** * Creates a Break variant of ControlFlow * @param value Break value */ export declare function Break(value: B): ControlFlow; export {};