iterflow 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +228 -0
- package/dist/fn/index.cjs +904 -0
- package/dist/fn/index.cjs.map +1 -0
- package/dist/fn/index.d.cts +1187 -0
- package/dist/fn/index.d.ts +1187 -0
- package/dist/fn/index.js +837 -0
- package/dist/fn/index.js.map +1 -0
- package/dist/index.cjs +4030 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2264 -0
- package/dist/index.d.ts +2264 -0
- package/dist/index.js +3977 -0
- package/dist/index.js.map +1 -0
- package/package.json +111 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/errors.ts","../../src/validation.ts","../../src/fn/composition.ts","../../src/fn/index.ts"],"names":["min","max","count","mean","sum","covariance","window"],"mappings":";AAQO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EACvB,SAAA;AAAA,EACA,OAAA;AAAA,EAEhB,WAAA,CACE,OAAA,EACA,SAAA,EACA,OAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AACjB,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAGf,IAAA,IAAI,MAAM,iBAAA,EAAmB;AAC3B,MAAA,KAAA,CAAM,iBAAA,CAAkB,IAAA,EAAM,IAAA,CAAK,WAAW,CAAA;AAAA,IAChD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAA,GAA2B;AACzB,IAAA,IAAI,MAAM,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,KAAK,OAAO,CAAA,CAAA;AAEvC,IAAA,IAAI,KAAK,SAAA,EAAW;AAClB,MAAA,GAAA,IAAO;AAAA,aAAA,EAAkB,KAAK,SAAS,CAAA,CA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EAA+C;AACzE,EAAA,OAAA,CAAQ,aAAkC;AACxC,IAAA,KAAA,MAAW,YAAY,SAAA,EAAW;AAChC,MAAA,OAAO,QAAA;AAAA,IACT;AAAA,EACF,CAAA,GAAG;AACL","file":"index.js","sourcesContent":["/**\n * Error handling utilities and custom error classes for iterflow\n * @module errors\n */\n\n/**\n * Base error class for all iterflow errors\n */\nexport class iterflowError extends Error {\n public readonly operation?: string;\n public readonly context?: Record<string, unknown>;\n\n constructor(\n message: string,\n operation?: string,\n context?: Record<string, unknown>,\n ) {\n super(message);\n this.name = \"iterflowError\";\n this.operation = operation;\n this.context = context;\n\n // Maintain proper stack trace for where our error was thrown\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n /**\n * Returns a detailed error message with context\n */\n toDetailedString(): string {\n let msg = `${this.name}: ${this.message}`;\n\n if (this.operation) {\n msg += `\\n Operation: ${this.operation}`;\n }\n\n if (this.context && Object.keys(this.context).length > 0) {\n msg += \"\\n Context:\";\n for (const [key, value] of Object.entries(this.context)) {\n msg += `\\n ${key}: ${JSON.stringify(value)}`;\n }\n }\n\n if (this.stack) {\n msg += `\\n Stack: ${this.stack.split(\"\\n\").slice(1).join(\"\\n\")}`;\n }\n\n return msg;\n }\n}\n\n/**\n * Error thrown when operation parameters are invalid\n */\nexport class ValidationError extends iterflowError {\n constructor(\n message: string,\n operation?: string,\n context?: Record<string, unknown>,\n ) {\n super(message, operation, context);\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Error thrown when an operation fails during execution\n */\nexport class OperationError extends iterflowError {\n public readonly cause?: Error;\n\n constructor(\n message: string,\n operation?: string,\n cause?: Error,\n context?: Record<string, unknown>,\n ) {\n super(message, operation, context);\n this.name = \"OperationError\";\n this.cause = cause;\n }\n\n toDetailedString(): string {\n let msg = super.toDetailedString();\n\n if (this.cause) {\n msg += `\\n Caused by: ${this.cause.message}`;\n if (this.cause.stack) {\n msg += `\\n ${this.cause.stack}`;\n }\n }\n\n return msg;\n }\n}\n\n/**\n * Error thrown when an operation requires a non-empty sequence\n */\nexport class EmptySequenceError extends iterflowError {\n constructor(operation: string, message?: string) {\n super(\n message || `Operation '${operation}' requires a non-empty sequence`,\n operation,\n );\n this.name = \"EmptySequenceError\";\n }\n}\n\n/**\n * Error thrown when accessing an invalid index\n */\nexport class IndexOutOfBoundsError extends iterflowError {\n public readonly index: number;\n public readonly size?: number;\n\n constructor(index: number, size?: number, operation?: string) {\n const sizeInfo = size !== undefined ? ` (size: ${size})` : \"\";\n super(`Index ${index} is out of bounds${sizeInfo}`, operation, {\n index,\n size,\n });\n this.name = \"IndexOutOfBoundsError\";\n this.index = index;\n this.size = size;\n }\n}\n\n/**\n * Error thrown when a type conversion or coercion fails\n */\nexport class TypeConversionError extends iterflowError {\n public readonly value: unknown;\n public readonly expectedType: string;\n\n constructor(value: unknown, expectedType: string, operation?: string) {\n super(\n `Cannot convert value ${JSON.stringify(value)} to type ${expectedType}`,\n operation,\n { value, expectedType },\n );\n this.name = \"TypeConversionError\";\n this.value = value;\n this.expectedType = expectedType;\n }\n}\n","/**\n * Input validation utilities for iterflow operations\n * @module validation\n */\n\nimport { ValidationError, TypeConversionError } from \"./errors.js\";\n\n/**\n * Validates that a value is a positive integer\n */\nexport function validatePositiveInteger(\n value: number,\n paramName: string,\n operation?: string,\n): void {\n if (!Number.isInteger(value)) {\n throw new ValidationError(\n `${paramName} must be an integer, got ${value}`,\n operation,\n { paramName, value },\n );\n }\n\n if (value < 1) {\n throw new ValidationError(\n `${paramName} must be at least 1, got ${value}`,\n operation,\n { paramName, value },\n );\n }\n}\n\n/**\n * Validates that a value is a non-negative integer\n */\nexport function validateNonNegativeInteger(\n value: number,\n paramName: string,\n operation?: string,\n): void {\n if (!Number.isInteger(value)) {\n throw new ValidationError(\n `${paramName} must be an integer, got ${value}`,\n operation,\n { paramName, value },\n );\n }\n\n if (value < 0) {\n throw new ValidationError(\n `${paramName} must be non-negative, got ${value}`,\n operation,\n { paramName, value },\n );\n }\n}\n\n/**\n * Validates that a value is within a specific range\n */\nexport function validateRange(\n value: number,\n min: number,\n max: number,\n paramName: string,\n operation?: string,\n): void {\n if (value < min || value > max) {\n throw new ValidationError(\n `${paramName} must be between ${min} and ${max}, got ${value}`,\n operation,\n { paramName, value, min, max },\n );\n }\n}\n\n/**\n * Validates that a value is a finite number (not NaN or Infinity)\n */\nexport function validateFiniteNumber(\n value: number,\n paramName: string,\n operation?: string,\n): void {\n if (!Number.isFinite(value)) {\n throw new ValidationError(\n `${paramName} must be a finite number, got ${value}`,\n operation,\n { paramName, value },\n );\n }\n}\n\n/**\n * Validates that a value is not zero\n */\nexport function validateNonZero(\n value: number,\n paramName: string,\n operation?: string,\n): void {\n if (value === 0) {\n throw new ValidationError(`${paramName} cannot be zero`, operation, {\n paramName,\n value,\n });\n }\n}\n\n/**\n * Validates that a value is a function\n */\nexport function validateFunction(\n value: unknown,\n paramName: string,\n operation?: string,\n): asserts value is Function {\n if (typeof value !== \"function\") {\n throw new ValidationError(\n `${paramName} must be a function, got ${typeof value}`,\n operation,\n { paramName, type: typeof value },\n );\n }\n}\n\n/**\n * Validates that a value is iterable\n */\nexport function validateIterable<T>(\n value: unknown,\n paramName: string,\n operation?: string,\n): asserts value is Iterable<T> {\n if (value == null || typeof (value as any)[Symbol.iterator] !== \"function\") {\n throw new ValidationError(`${paramName} must be iterable`, operation, {\n paramName,\n type: typeof value,\n });\n }\n}\n\n/**\n * Validates that a value is a valid comparator function\n */\nexport function validateComparator<T>(\n fn: unknown,\n operation?: string,\n): asserts fn is (a: T, b: T) => number {\n validateFunction(fn, \"comparator\", operation);\n\n // Optional: Test with sample values if needed\n // This is a basic check - actual validation happens at runtime\n}\n\n/**\n * Validates that an array is not empty\n */\nexport function validateNonEmpty<T>(arr: T[], operation?: string): void {\n if (arr.length === 0) {\n throw new ValidationError(\"Sequence cannot be empty\", operation);\n }\n}\n\n/**\n * Safely converts a value to a number\n */\nexport function toNumber(\n value: unknown,\n operation?: string,\n): number {\n const num = Number(value);\n\n if (Number.isNaN(num)) {\n throw new TypeConversionError(value, \"number\", operation);\n }\n\n return num;\n}\n\n/**\n * Safely converts a value to an integer\n */\nexport function toInteger(\n value: unknown,\n operation?: string,\n): number {\n const num = toNumber(value, operation);\n const int = Math.trunc(num);\n\n if (num !== int) {\n throw new TypeConversionError(value, \"integer\", operation);\n }\n\n return int;\n}\n\n/**\n * Validates array index\n */\nexport function validateIndex(\n index: number,\n size: number,\n operation?: string,\n): void {\n validateNonNegativeInteger(index, \"index\", operation);\n\n if (index >= size) {\n throw new ValidationError(\n `Index ${index} is out of bounds for size ${size}`,\n operation,\n { index, size },\n );\n }\n}\n\n/**\n * Validates that a number is a safe integer within JavaScript's safe integer range\n * @param value - The value to validate\n * @param paramName - The parameter name for error messages\n * @param operation - The operation name for error context\n */\nexport function validateSafeInteger(\n value: number,\n paramName: string,\n operation?: string,\n): void {\n if (!Number.isSafeInteger(value)) {\n throw new ValidationError(\n `${paramName} must be a safe integer (${Number.MIN_SAFE_INTEGER} to ${Number.MAX_SAFE_INTEGER}), got ${value}`,\n operation,\n { paramName, value },\n );\n }\n}\n\n/**\n * Validates that a window/chunk size is within reasonable bounds\n * @param size - The size to validate\n * @param maxSize - The maximum allowed size (default: 1,000,000)\n * @param operation - The operation name for error context\n */\nexport function validateWindowSize(\n size: number,\n maxSize: number = 1_000_000,\n operation?: string,\n): void {\n validatePositiveInteger(size, \"size\", operation);\n\n if (size > maxSize) {\n throw new ValidationError(\n `Window size ${size} exceeds maximum allowed size ${maxSize}. Consider using smaller windows or streaming operations.`,\n operation,\n { size, maxSize },\n );\n }\n}\n\n/**\n * Validates that an array size is within reasonable memory bounds\n * @param size - The estimated size\n * @param maxElements - The maximum allowed elements (default: 10,000,000)\n * @param operation - The operation name for error context\n */\nexport function validateMemoryLimit(\n size: number,\n maxElements: number = 10_000_000,\n operation?: string,\n): void {\n validateNonNegativeInteger(size, \"size\", operation);\n\n if (size > maxElements) {\n throw new ValidationError(\n `Operation would exceed memory limit (${size} elements > ${maxElements} maximum). Consider using streaming operations with take() or chunk().`,\n operation,\n { size, maxElements },\n );\n }\n}\n","// Composition utilities for functional programming with iterables\n\n/**\n * Type representing a function that transforms an iterable.\n * Used for composing transformations in a type-safe way.\n *\n * @template T The input element type\n * @template U The output element type\n */\nexport type IterableTransformer<T, U> = (\n iterable: Iterable<T>,\n) => IterableIterator<U>;\n\n/**\n * Type representing a terminal operation that produces a final result.\n *\n * @template T The input element type\n * @template R The result type\n */\nexport type TerminalOperation<T, R> = (iterable: Iterable<T>) => R;\n\n/**\n * Composes functions from left to right (Unix pipe style).\n * Each function takes an iterable and returns an iterable, except the last\n * function which can return any type.\n *\n * The pipe flows data from left to right:\n * pipe(f, g, h)(x) === h(g(f(x)))\n *\n * @param fns - Functions to compose from left to right\n * @returns A function that applies all transformations in sequence\n * @example\n * ```typescript\n * import { pipe, map, filter, toArray } from 'iterflow/fn';\n *\n * const process = pipe(\n * map((x: number) => x * 2),\n * filter((x: number) => x > 5),\n * toArray\n * );\n *\n * process([1, 2, 3, 4, 5]); // [6, 8, 10]\n * ```\n */\nexport function pipe<A, B>(fn1: (input: A) => B): (input: A) => B;\n\nexport function pipe<A, B, C>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n): (input: A) => C;\n\nexport function pipe<A, B, C, D>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n): (input: A) => D;\n\nexport function pipe<A, B, C, D, E>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n fn4: (input: D) => E,\n): (input: A) => E;\n\nexport function pipe<A, B, C, D, E, F>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n fn4: (input: D) => E,\n fn5: (input: E) => F,\n): (input: A) => F;\n\nexport function pipe<A, B, C, D, E, F, G>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n fn4: (input: D) => E,\n fn5: (input: E) => F,\n fn6: (input: F) => G,\n): (input: A) => G;\n\nexport function pipe<A, B, C, D, E, F, G, H>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n fn4: (input: D) => E,\n fn5: (input: E) => F,\n fn6: (input: F) => G,\n fn7: (input: G) => H,\n): (input: A) => H;\n\nexport function pipe<A, B, C, D, E, F, G, H, I>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n fn4: (input: D) => E,\n fn5: (input: E) => F,\n fn6: (input: F) => G,\n fn7: (input: G) => H,\n fn8: (input: H) => I,\n): (input: A) => I;\n\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n fn4: (input: D) => E,\n fn5: (input: E) => F,\n fn6: (input: F) => G,\n fn7: (input: G) => H,\n fn8: (input: H) => I,\n fn9: (input: I) => J,\n): (input: A) => J;\n\nexport function pipe<A, B, C, D, E, F, G, H, I, J, K>(\n fn1: (input: A) => B,\n fn2: (input: B) => C,\n fn3: (input: C) => D,\n fn4: (input: D) => E,\n fn5: (input: E) => F,\n fn6: (input: F) => G,\n fn7: (input: G) => H,\n fn8: (input: H) => I,\n fn9: (input: I) => J,\n fn10: (input: J) => K,\n): (input: A) => K;\n\nexport function pipe(...fns: Array<(input: any) => any>): (input: any) => any {\n return (input: any) => fns.reduce((acc, fn) => fn(acc), input);\n}\n\n/**\n * Composes functions from right to left (traditional mathematical composition).\n * Each function takes an iterable and returns an iterable, except the last\n * function which can return any type.\n *\n * The composition flows from right to left:\n * compose(h, g, f)(x) === h(g(f(x)))\n *\n * @param fns - Functions to compose from right to left\n * @returns A function that applies all transformations in sequence\n * @example\n * ```typescript\n * import { compose, map, filter, toArray } from 'iterflow/fn';\n *\n * const process = compose(\n * toArray,\n * filter((x: number) => x > 5),\n * map((x: number) => x * 2)\n * );\n *\n * process([1, 2, 3, 4, 5]); // [6, 8, 10]\n * ```\n */\nexport function compose<A, B>(fn1: (input: A) => B): (input: A) => B;\n\nexport function compose<A, B, C>(\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => C;\n\nexport function compose<A, B, C, D>(\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => D;\n\nexport function compose<A, B, C, D, E>(\n fn4: (input: D) => E,\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => E;\n\nexport function compose<A, B, C, D, E, F>(\n fn5: (input: E) => F,\n fn4: (input: D) => E,\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => F;\n\nexport function compose<A, B, C, D, E, F, G>(\n fn6: (input: F) => G,\n fn5: (input: E) => F,\n fn4: (input: D) => E,\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => G;\n\nexport function compose<A, B, C, D, E, F, G, H>(\n fn7: (input: G) => H,\n fn6: (input: F) => G,\n fn5: (input: E) => F,\n fn4: (input: D) => E,\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => H;\n\nexport function compose<A, B, C, D, E, F, G, H, I>(\n fn8: (input: H) => I,\n fn7: (input: G) => H,\n fn6: (input: F) => G,\n fn5: (input: E) => F,\n fn4: (input: D) => E,\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => I;\n\nexport function compose<A, B, C, D, E, F, G, H, I, J>(\n fn9: (input: I) => J,\n fn8: (input: H) => I,\n fn7: (input: G) => H,\n fn6: (input: F) => G,\n fn5: (input: E) => F,\n fn4: (input: D) => E,\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => J;\n\nexport function compose<A, B, C, D, E, F, G, H, I, J, K>(\n fn10: (input: J) => K,\n fn9: (input: I) => J,\n fn8: (input: H) => I,\n fn7: (input: G) => H,\n fn6: (input: F) => G,\n fn5: (input: E) => F,\n fn4: (input: D) => E,\n fn3: (input: C) => D,\n fn2: (input: B) => C,\n fn1: (input: A) => B,\n): (input: A) => K;\n\nexport function compose(\n ...fns: Array<(input: any) => any>\n): (input: any) => any {\n return (input: any) => fns.reduceRight((acc, fn) => fn(acc), input);\n}\n\n/**\n * Helper function to create custom iterable operations that follow the\n * iterflow functional API pattern.\n *\n * Creates a curried function that takes configuration parameters and returns\n * a function that transforms an iterable. The transformation uses a generator\n * function for lazy evaluation.\n *\n * @template TConfig The type of configuration parameters\n * @template TInput The type of input elements\n * @template TOutput The type of output elements\n * @param name - Name of the operation (for debugging)\n * @param generator - Generator function that performs the transformation\n * @returns A curried function following the iterflow pattern\n * @example\n * ```typescript\n * import { createOperation } from 'iterflow/fn';\n *\n * // Create a custom operation that multiplies by a factor\n * const multiplyBy = createOperation(\n * 'multiplyBy',\n * function* (iterable: Iterable<number>, factor: number) {\n * for (const value of iterable) {\n * yield value * factor;\n * }\n * }\n * );\n *\n * // Use it in a pipeline\n * const double = multiplyBy(2);\n * Array.from(double([1, 2, 3])); // [2, 4, 6]\n *\n * // Create a custom filtering operation\n * const between = createOperation(\n * 'between',\n * function* (iterable: Iterable<number>, min: number, max: number) {\n * for (const value of iterable) {\n * if (value >= min && value <= max) {\n * yield value;\n * }\n * }\n * }\n * );\n *\n * const between5And10 = between(5, 10);\n * Array.from(between5And10([1, 6, 3, 8, 12, 4])); // [6, 8]\n * ```\n */\nexport function createOperation<TInput, TOutput>(\n name: string,\n generator: (iterable: Iterable<TInput>) => Generator<TOutput>,\n): (iterable: Iterable<TInput>) => IterableIterator<TOutput>;\n\nexport function createOperation<TConfig, TInput, TOutput>(\n name: string,\n generator: (\n iterable: Iterable<TInput>,\n config: TConfig,\n ) => Generator<TOutput>,\n): (\n config: TConfig,\n) => (iterable: Iterable<TInput>) => IterableIterator<TOutput>;\n\nexport function createOperation<TConfig1, TConfig2, TInput, TOutput>(\n name: string,\n generator: (\n iterable: Iterable<TInput>,\n config1: TConfig1,\n config2: TConfig2,\n ) => Generator<TOutput>,\n): (\n config1: TConfig1,\n config2: TConfig2,\n) => (iterable: Iterable<TInput>) => IterableIterator<TOutput>;\n\nexport function createOperation<TConfig1, TConfig2, TConfig3, TInput, TOutput>(\n name: string,\n generator: (\n iterable: Iterable<TInput>,\n config1: TConfig1,\n config2: TConfig2,\n config3: TConfig3,\n ) => Generator<TOutput>,\n): (\n config1: TConfig1,\n config2: TConfig2,\n config3: TConfig3,\n) => (iterable: Iterable<TInput>) => IterableIterator<TOutput>;\n\nexport function createOperation<TInput, TOutput>(\n name: string,\n generator: (\n iterable: Iterable<TInput>,\n ...configs: any[]\n ) => Generator<TOutput>,\n): any;\nexport function createOperation<TInput, TOutput>(\n name: string,\n generator: (\n iterable: Iterable<TInput>,\n ...configs: any[]\n ) => Generator<TOutput>,\n): any {\n // Handle operations with no configuration parameters\n if (generator.length === 1) {\n return (iterable: Iterable<TInput>): IterableIterator<TOutput> => {\n const result = generator(iterable);\n // Add operation name for debugging\n Object.defineProperty(result, \"name\", { value: name });\n return result;\n };\n }\n\n // Handle operations with configuration parameters (curried)\n return (...configs: any[]) => {\n return (iterable: Iterable<TInput>): IterableIterator<TOutput> => {\n const result = generator(iterable, ...configs);\n // Add operation name for debugging\n Object.defineProperty(result, \"name\", { value: name });\n return result;\n };\n };\n}\n\n/**\n * Type representing a transducer - a composable algorithmic transformation.\n * Transducers are independent of the context of their input and output sources.\n *\n * @template TInput The input element type\n * @template TOutput The output element type\n */\nexport type Transducer<TInput, TOutput> = <TResult>(\n reducer: Reducer<TOutput, TResult>,\n) => Reducer<TInput, TResult>;\n\n/**\n * Type representing a reducer function that combines values into an accumulator.\n *\n * @template T The type of values being reduced\n * @template TResult The type of the accumulator\n */\nexport type Reducer<T, TResult> = (accumulator: TResult, value: T) => TResult;\n\n/**\n * Creates a transducer from a map function.\n * Transducers enable efficient composition of transformations without\n * creating intermediate iterables.\n *\n * @template TInput The input element type\n * @template TOutput The output element type\n * @param fn - Function to transform each element\n * @returns A transducer that applies the transformation\n * @example\n * ```typescript\n * import { mapTransducer, transduce } from 'iterflow/fn';\n *\n * const xf = mapTransducer((x: number) => x * 2);\n * const result = transduce(\n * xf,\n * (acc: number[], x: number) => [...acc, x],\n * [],\n * [1, 2, 3]\n * );\n * // [2, 4, 6]\n * ```\n */\nexport function mapTransducer<TInput, TOutput>(\n fn: (value: TInput) => TOutput,\n): Transducer<TInput, TOutput> {\n return <TResult>(reducer: Reducer<TOutput, TResult>) => {\n return (accumulator: TResult, value: TInput): TResult => {\n return reducer(accumulator, fn(value));\n };\n };\n}\n\n/**\n * Creates a transducer from a filter predicate.\n * Transducers enable efficient composition of transformations without\n * creating intermediate iterables.\n *\n * @template T The element type\n * @param predicate - Function to test each element\n * @returns A transducer that filters elements\n * @example\n * ```typescript\n * import { filterTransducer, transduce } from 'iterflow/fn';\n *\n * const xf = filterTransducer((x: number) => x % 2 === 0);\n * const result = transduce(\n * xf,\n * (acc: number[], x: number) => [...acc, x],\n * [],\n * [1, 2, 3, 4, 5]\n * );\n * // [2, 4]\n * ```\n */\nexport function filterTransducer<T>(\n predicate: (value: T) => boolean,\n): Transducer<T, T> {\n return <TResult>(reducer: Reducer<T, TResult>) => {\n return (accumulator: TResult, value: T): TResult => {\n return predicate(value) ? reducer(accumulator, value) : accumulator;\n };\n };\n}\n\n/**\n * Creates a transducer from a take operation.\n * Transducers enable efficient composition of transformations without\n * creating intermediate iterables.\n *\n * Note: This transducer requires special handling in transduce() to support\n * early termination. Use the '@@transducer/reduced' protocol.\n *\n * @template T The element type\n * @param n - Number of elements to take\n * @returns A transducer that takes the first n elements\n * @example\n * ```typescript\n * import { takeTransducer, transduce } from 'iterflow/fn';\n *\n * const xf = takeTransducer(3);\n * const result = transduce(\n * xf,\n * (acc: number[], x: number) => [...acc, x],\n * [],\n * [1, 2, 3, 4, 5]\n * );\n * // [1, 2, 3]\n * ```\n */\nexport function takeTransducer<T>(n: number): Transducer<T, T> {\n return <TResult>(reducer: Reducer<T, TResult>) => {\n let taken = 0;\n return (accumulator: TResult, value: T): TResult => {\n if (taken < n) {\n taken++;\n const result = reducer(accumulator, value);\n // Mark as reduced if we've taken enough\n if (taken === n) {\n return reduced(result) as TResult;\n }\n return result;\n }\n return accumulator;\n };\n };\n}\n\n/**\n * Composes multiple transducers into a single transducer.\n * Composition happens from right to left (like compose).\n *\n * @param transducers - Transducers to compose\n * @returns A composed transducer\n * @example\n * ```typescript\n * import { composeTransducers, mapTransducer, filterTransducer, transduce } from 'iterflow/fn';\n *\n * const xf = composeTransducers(\n * filterTransducer((x: number) => x > 2),\n * mapTransducer((x: number) => x * 2)\n * );\n *\n * const result = transduce(\n * xf,\n * (acc: number[], x: number) => [...acc, x],\n * [],\n * [1, 2, 3, 4, 5]\n * );\n * // [6, 8, 10]\n * ```\n */\nexport function composeTransducers<A, B>(\n xf1: Transducer<A, B>,\n): Transducer<A, B>;\n\nexport function composeTransducers<A, B, C>(\n xf2: Transducer<B, C>,\n xf1: Transducer<A, B>,\n): Transducer<A, C>;\n\nexport function composeTransducers<A, B, C, D>(\n xf3: Transducer<C, D>,\n xf2: Transducer<B, C>,\n xf1: Transducer<A, B>,\n): Transducer<A, D>;\n\nexport function composeTransducers<A, B, C, D, E>(\n xf4: Transducer<D, E>,\n xf3: Transducer<C, D>,\n xf2: Transducer<B, C>,\n xf1: Transducer<A, B>,\n): Transducer<A, E>;\n\nexport function composeTransducers(\n ...transducers: Array<Transducer<any, any>>\n): Transducer<any, any> {\n return (reducer: Reducer<any, any>) => {\n return transducers.reduceRight((acc, xf) => xf(acc), reducer);\n };\n}\n\n/**\n * Symbol used to mark a reduced value (for early termination in transducers).\n */\nconst REDUCED = Symbol(\"@@transducer/reduced\");\n\n/**\n * Interface for a reduced value (supports early termination).\n */\ninterface Reduced<T> {\n [REDUCED]: true;\n value: T;\n}\n\n/**\n * Marks a value as reduced (for early termination in transducers).\n *\n * @template T The value type\n * @param value - The value to mark as reduced\n * @returns A reduced value\n */\nexport function reduced<T>(value: T): Reduced<T> {\n return {\n [REDUCED]: true,\n value,\n };\n}\n\n/**\n * Checks if a value is reduced.\n *\n * @template T The value type\n * @param value - The value to check\n * @returns true if the value is reduced\n */\nexport function isReduced<T>(value: any): value is Reduced<T> {\n return value != null && value[REDUCED] === true;\n}\n\n/**\n * Applies a transducer to an iterable and reduces it to a final value.\n * This is the main entry point for using transducers.\n *\n * @template TInput The input element type\n * @template TOutput The output element type (after transducer transformation)\n * @template TResult The final result type\n * @param transducer - The transducer to apply\n * @param reducer - The reducer function to combine values\n * @param initial - The initial accumulator value\n * @param iterable - The iterable to process\n * @returns The final reduced value\n * @example\n * ```typescript\n * import { transduce, composeTransducers, mapTransducer, filterTransducer } from 'iterflow/fn';\n *\n * const xf = composeTransducers(\n * filterTransducer((x: number) => x % 2 === 0),\n * mapTransducer((x: number) => x * 2)\n * );\n *\n * const sum = transduce(\n * xf,\n * (acc: number, x: number) => acc + x,\n * 0,\n * [1, 2, 3, 4, 5]\n * );\n * // 12 (2*2 + 4*2)\n *\n * const toArray = transduce(\n * xf,\n * (acc: number[], x: number) => [...acc, x],\n * [],\n * [1, 2, 3, 4, 5]\n * );\n * // [4, 8]\n * ```\n */\nexport function transduce<TInput, TOutput, TResult>(\n transducer: Transducer<TInput, TOutput>,\n reducer: Reducer<TOutput, TResult>,\n initial: TResult,\n iterable: Iterable<TInput>,\n): TResult {\n const xform = transducer(reducer);\n let accumulator = initial;\n\n for (const value of iterable) {\n accumulator = xform(accumulator, value);\n // Check for early termination\n if (isReduced<TResult>(accumulator)) {\n return accumulator.value;\n }\n }\n\n return accumulator;\n}\n\n/**\n * Converts a transducer into an iterable transformer.\n * This allows transducers to be used in pipe() and compose() with other\n * iterable operations.\n *\n * @template TInput The input element type\n * @template TOutput The output element type\n * @param transducer - The transducer to convert\n * @returns An iterable transformer function\n * @example\n * ```typescript\n * import { pipe, transducerToIterator, mapTransducer, filterTransducer, toArray } from 'iterflow/fn';\n *\n * const xf = composeTransducers(\n * filterTransducer((x: number) => x % 2 === 0),\n * mapTransducer((x: number) => x * 2)\n * );\n *\n * const process = pipe(\n * transducerToIterator(xf),\n * toArray\n * );\n *\n * process([1, 2, 3, 4, 5]); // [4, 8]\n * ```\n */\nexport function transducerToIterator<TInput, TOutput>(\n transducer: Transducer<TInput, TOutput>,\n): (iterable: Iterable<TInput>) => IterableIterator<TOutput> {\n return function* (iterable: Iterable<TInput>): IterableIterator<TOutput> {\n // Create a reducer that yields values immediately\n const results: TOutput[] = [];\n const reducer = (acc: TOutput[], value: TOutput): TOutput[] => {\n acc.push(value);\n return acc;\n };\n\n const xform = transducer(reducer);\n\n for (const value of iterable) {\n const before = results.length;\n const result = xform(results, value);\n\n // Check for early termination\n if (isReduced<TOutput[]>(result)) {\n // Yield any new values that were added\n for (let i = before; i < result.value.length; i++) {\n yield result.value[i]!;\n }\n return;\n }\n\n // Yield any new values that were added\n for (let i = before; i < results.length; i++) {\n yield results[i]!;\n }\n }\n };\n}\n","// Functional API exports - for functional programming style usage\n// Usage: import { sum, filter, map } from 'iterflow/fn';\n\nimport {\n validateRange,\n validatePositiveInteger,\n validateNonZero,\n} from \"../validation.js\";\n\n// Statistical operations\n/**\n * Calculates the sum of all numeric elements in an iterable.\n *\n * @param iterable - The iterable of numbers to sum\n * @returns The sum of all elements\n * @example\n * ```typescript\n * sum([1, 2, 3, 4, 5]); // 15\n * ```\n */\nexport function sum(iterable: Iterable<number>): number {\n let total = 0;\n for (const value of iterable) {\n total += value;\n }\n return total;\n}\n\n/**\n * Calculates the arithmetic mean (average) of all numeric elements.\n *\n * @param iterable - The iterable of numbers\n * @returns The mean value, or undefined if the iterable is empty\n * @example\n * ```typescript\n * mean([1, 2, 3, 4, 5]); // 3\n * mean([]); // undefined\n * ```\n */\nexport function mean(iterable: Iterable<number>): number | undefined {\n let total = 0;\n let count = 0;\n for (const value of iterable) {\n total += value;\n count++;\n }\n return count === 0 ? undefined : total / count;\n}\n\n/**\n * Finds the minimum value among all numeric elements.\n *\n * @param iterable - The iterable of numbers\n * @returns The minimum value, or undefined if the iterable is empty\n * @example\n * ```typescript\n * min([3, 1, 4, 1, 5]); // 1\n * min([]); // undefined\n * ```\n */\nexport function min(iterable: Iterable<number>): number | undefined {\n let minimum: number | undefined = undefined;\n for (const value of iterable) {\n if (minimum === undefined || value < minimum) {\n minimum = value;\n }\n }\n return minimum;\n}\n\n/**\n * Finds the maximum value among all numeric elements.\n *\n * @param iterable - The iterable of numbers\n * @returns The maximum value, or undefined if the iterable is empty\n * @example\n * ```typescript\n * max([3, 1, 4, 1, 5]); // 5\n * max([]); // undefined\n * ```\n */\nexport function max(iterable: Iterable<number>): number | undefined {\n let maximum: number | undefined = undefined;\n for (const value of iterable) {\n if (maximum === undefined || value > maximum) {\n maximum = value;\n }\n }\n return maximum;\n}\n\n/**\n * Counts the total number of elements in an iterable.\n *\n * @template T The type of elements in the iterable\n * @param iterable - The iterable to count\n * @returns The total count of elements\n * @example\n * ```typescript\n * count([1, 2, 3, 4, 5]); // 5\n * count([]); // 0\n * ```\n */\nexport function count<T>(iterable: Iterable<T>): number {\n let count = 0;\n for (const _ of iterable) {\n count++;\n }\n return count;\n}\n\n/**\n * Calculates the median value of all numeric elements.\n * The median is the middle value when elements are sorted.\n *\n * @param iterable - The iterable of numbers\n * @returns The median value, or undefined if the iterable is empty\n * @example\n * ```typescript\n * median([1, 2, 3, 4, 5]); // 3\n * median([1, 2, 3, 4]); // 2.5\n * median([]); // undefined\n * ```\n */\nexport function median(iterable: Iterable<number>): number | undefined {\n const values = Array.from(iterable);\n if (values.length === 0) return undefined;\n\n values.sort((a, b) => a - b);\n const mid = Math.floor(values.length / 2);\n\n if (values.length % 2 === 0) {\n return (values[mid - 1]! + values[mid]!) / 2;\n } else {\n return values[mid]!;\n }\n}\n\n/**\n * Calculates the variance of all numeric elements.\n * Variance measures how far each number in the set is from the mean.\n *\n * @param iterable - The iterable of numbers\n * @returns The variance, or undefined if the iterable is empty\n * @example\n * ```typescript\n * variance([1, 2, 3, 4, 5]); // 2\n * variance([]); // undefined\n * ```\n */\nexport function variance(iterable: Iterable<number>): number | undefined {\n const values = Array.from(iterable);\n if (values.length === 0) return undefined;\n\n const mean = values.reduce((sum, val) => sum + val, 0) / values.length;\n\n // Optimize: calculate sum of squared differences in single pass without intermediate array\n let sumSquaredDiffs = 0;\n for (let i = 0; i < values.length; i++) {\n const diff = values[i]! - mean;\n sumSquaredDiffs += diff * diff;\n }\n\n return sumSquaredDiffs / values.length;\n}\n\n/**\n * Calculates the standard deviation of all numeric elements.\n * Standard deviation is the square root of variance and measures dispersion.\n *\n * @param iterable - The iterable of numbers\n * @returns The standard deviation, or undefined if the iterable is empty\n * @example\n * ```typescript\n * stdDev([2, 4, 4, 4, 5, 5, 7, 9]); // ~2\n * stdDev([]); // undefined\n * ```\n */\nexport function stdDev(iterable: Iterable<number>): number | undefined {\n const varianceValue = variance(iterable);\n return varianceValue === undefined ? undefined : Math.sqrt(varianceValue);\n}\n\n/**\n * Calculates the specified percentile of all numeric elements.\n * Uses linear interpolation between closest ranks.\n *\n * @param iterable - The iterable of numbers\n * @param p - The percentile to calculate (0-100)\n * @returns The percentile value, or undefined if the iterable is empty\n * @throws {Error} If p is not between 0 and 100\n * @example\n * ```typescript\n * percentile([1, 2, 3, 4, 5], 50); // 3 (median)\n * percentile([1, 2, 3, 4, 5], 75); // 4\n * percentile([], 50); // undefined\n * ```\n */\nexport function percentile(\n iterable: Iterable<number>,\n p: number,\n): number | undefined {\n validateRange(p, 0, 100, \"percentile\", \"percentile\");\n\n const values = Array.from(iterable);\n if (values.length === 0) return undefined;\n\n values.sort((a, b) => a - b);\n\n if (p === 0) return values[0];\n if (p === 100) return values[values.length - 1];\n\n const index = (p / 100) * (values.length - 1);\n const lower = Math.floor(index);\n const upper = Math.ceil(index);\n\n if (lower === upper) {\n return values[lower]!;\n }\n\n const weight = index - lower;\n return values[lower]! * (1 - weight) + values[upper]! * weight;\n}\n\n/**\n * Finds the most frequent value(s) in the dataset.\n * Returns an array of all values that appear most frequently.\n *\n * @param iterable - The iterable of numbers\n * @returns An array of the most frequent value(s), or undefined if the iterable is empty\n * @example\n * ```typescript\n * mode([1, 2, 2, 3, 3, 3]); // [3]\n * mode([1, 1, 2, 2, 3]); // [1, 2] (bimodal)\n * mode([]); // undefined\n * ```\n */\nexport function mode(iterable: Iterable<number>): number[] | undefined {\n const values = Array.from(iterable);\n if (values.length === 0) return undefined;\n\n const frequency = new Map<number, number>();\n let maxFreq = 0;\n\n for (const value of values) {\n const count = (frequency.get(value) || 0) + 1;\n frequency.set(value, count);\n maxFreq = Math.max(maxFreq, count);\n }\n\n const modes: number[] = [];\n for (const [value, freq] of frequency) {\n if (freq === maxFreq) {\n modes.push(value);\n }\n }\n\n return modes.sort((a, b) => a - b);\n}\n\n/**\n * Calculates the quartiles (Q1, Q2, Q3) of all numeric elements.\n * Q1 is the 25th percentile, Q2 is the median (50th percentile), Q3 is the 75th percentile.\n *\n * @param iterable - The iterable of numbers\n * @returns An object with Q1, Q2, and Q3 values, or undefined if the iterable is empty\n * @example\n * ```typescript\n * quartiles([1, 2, 3, 4, 5, 6, 7, 8, 9]);\n * // { Q1: 3, Q2: 5, Q3: 7 }\n * quartiles([]); // undefined\n * ```\n */\nexport function quartiles(\n iterable: Iterable<number>,\n): { Q1: number; Q2: number; Q3: number } | undefined {\n const values = Array.from(iterable);\n if (values.length === 0) return undefined;\n\n values.sort((a, b) => a - b);\n\n const calculatePercentile = (p: number): number => {\n if (p === 0) return values[0]!;\n if (p === 100) return values[values.length - 1]!;\n\n const index = (p / 100) * (values.length - 1);\n const lower = Math.floor(index);\n const upper = Math.ceil(index);\n\n if (lower === upper) {\n return values[lower]!;\n }\n\n const weight = index - lower;\n return values[lower]! * (1 - weight) + values[upper]! * weight;\n };\n\n return {\n Q1: calculatePercentile(25),\n Q2: calculatePercentile(50),\n Q3: calculatePercentile(75),\n };\n}\n\n/**\n * Calculates the span (range from minimum to maximum value) of all numeric elements.\n *\n * @param iterable - The iterable of numbers\n * @returns The span (max - min), or undefined if the iterable is empty\n * @example\n * ```typescript\n * span([1, 2, 3, 4, 5]); // 4\n * span([10]); // 0\n * span([]); // undefined\n * ```\n */\nexport function span(iterable: Iterable<number>): number | undefined {\n let minimum: number | undefined = undefined;\n let maximum: number | undefined = undefined;\n\n for (const value of iterable) {\n if (minimum === undefined || value < minimum) {\n minimum = value;\n }\n if (maximum === undefined || value > maximum) {\n maximum = value;\n }\n }\n\n return minimum === undefined || maximum === undefined\n ? undefined\n : maximum - minimum;\n}\n\n/**\n * Calculates the product of all numeric elements.\n *\n * @param iterable - The iterable of numbers\n * @returns The product of all elements, or 1 if the iterable is empty\n * @example\n * ```typescript\n * product([1, 2, 3, 4, 5]); // 120\n * product([2, 3, 4]); // 24\n * product([]); // 1\n * ```\n */\nexport function product(iterable: Iterable<number>): number {\n let result = 1;\n for (const value of iterable) {\n result *= value;\n }\n return result;\n}\n\n/**\n * Calculates the covariance between two numeric sequences.\n * Covariance measures the joint variability of two random variables.\n *\n * @param iter1 - The first iterable of numbers\n * @param iter2 - The second iterable of numbers\n * @returns The covariance, or undefined if either sequence is empty or sequences have different lengths\n * @example\n * ```typescript\n * covariance([1, 2, 3, 4, 5], [2, 4, 6, 8, 10]); // 4\n * covariance([], [1, 2, 3]); // undefined\n * ```\n */\nexport function covariance(\n iter1: Iterable<number>,\n iter2: Iterable<number>,\n): number | undefined {\n const values1 = Array.from(iter1);\n const values2 = Array.from(iter2);\n\n if (\n values1.length === 0 ||\n values2.length === 0 ||\n values1.length !== values2.length\n ) {\n return undefined;\n }\n\n const mean1 = values1.reduce((sum, val) => sum + val, 0) / values1.length;\n const mean2 = values2.reduce((sum, val) => sum + val, 0) / values2.length;\n\n let covariance = 0;\n for (let i = 0; i < values1.length; i++) {\n covariance += (values1[i]! - mean1) * (values2[i]! - mean2);\n }\n\n return covariance / values1.length;\n}\n\n/**\n * Calculates the Pearson correlation coefficient between two numeric sequences.\n * Correlation measures the strength and direction of the linear relationship between two variables.\n * Values range from -1 (perfect negative correlation) to 1 (perfect positive correlation).\n *\n * @param iter1 - The first iterable of numbers\n * @param iter2 - The second iterable of numbers\n * @returns The correlation coefficient, or undefined if either sequence is empty or sequences have different lengths\n * @example\n * ```typescript\n * correlation([1, 2, 3, 4, 5], [2, 4, 6, 8, 10]); // 1 (perfect positive correlation)\n * correlation([1, 2, 3], [3, 2, 1]); // -1 (perfect negative correlation)\n * correlation([], [1, 2, 3]); // undefined\n * ```\n */\nexport function correlation(\n iter1: Iterable<number>,\n iter2: Iterable<number>,\n): number | undefined {\n const values1 = Array.from(iter1);\n const values2 = Array.from(iter2);\n\n if (\n values1.length === 0 ||\n values2.length === 0 ||\n values1.length !== values2.length\n ) {\n return undefined;\n }\n\n const mean1 = values1.reduce((sum, val) => sum + val, 0) / values1.length;\n const mean2 = values2.reduce((sum, val) => sum + val, 0) / values2.length;\n\n let covariance = 0;\n let variance1 = 0;\n let variance2 = 0;\n\n for (let i = 0; i < values1.length; i++) {\n const diff1 = values1[i]! - mean1;\n const diff2 = values2[i]! - mean2;\n covariance += diff1 * diff2;\n variance1 += diff1 * diff1;\n variance2 += diff2 * diff2;\n }\n\n const stdDev1 = Math.sqrt(variance1 / values1.length);\n const stdDev2 = Math.sqrt(variance2 / values2.length);\n\n if (stdDev1 === 0 || stdDev2 === 0) {\n return undefined;\n }\n\n return covariance / (values1.length * stdDev1 * stdDev2);\n}\n\n// Transforming operations\n/**\n * Creates a curried function that transforms each element using the provided function.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of input elements\n * @template U The type of output elements\n * @param fn - Function to transform each element\n * @returns A function that transforms an iterable\n * @example\n * ```typescript\n * const double = map((x: number) => x * 2);\n * Array.from(double([1, 2, 3])); // [2, 4, 6]\n * ```\n */\nexport function map<T, U>(\n fn: (value: T) => U,\n): (iterable: Iterable<T>) => IterableIterator<U> {\n return function* (iterable: Iterable<T>): IterableIterator<U> {\n for (const value of iterable) {\n yield fn(value);\n }\n };\n}\n\n/**\n * Creates a curried function that filters elements based on a predicate.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that filters an iterable\n * @example\n * ```typescript\n * const evens = filter((x: number) => x % 2 === 0);\n * Array.from(evens([1, 2, 3, 4])); // [2, 4]\n * ```\n */\nexport function filter<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n for (const value of iterable) {\n if (predicate(value)) {\n yield value;\n }\n }\n };\n}\n\n/**\n * Creates a curried function that takes only the first `limit` elements.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param limit - Maximum number of elements to take\n * @returns A function that takes elements from an iterable\n * @example\n * ```typescript\n * const takeThree = take(3);\n * Array.from(takeThree([1, 2, 3, 4, 5])); // [1, 2, 3]\n * ```\n */\nexport function take<T>(\n limit: number,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n let count = 0;\n for (const value of iterable) {\n if (count >= limit) break;\n yield value;\n count++;\n }\n };\n}\n\n/**\n * Creates a curried function that skips the first `count` elements.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param count - Number of elements to skip\n * @returns A function that drops elements from an iterable\n * @example\n * ```typescript\n * const dropTwo = drop(2);\n * Array.from(dropTwo([1, 2, 3, 4, 5])); // [3, 4, 5]\n * ```\n */\nexport function drop<T>(\n count: number,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n let dropped = 0;\n for (const value of iterable) {\n if (dropped < count) {\n dropped++;\n continue;\n }\n yield value;\n }\n };\n}\n\n/**\n * Creates a curried function that maps each element to an iterable and flattens the results.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of input elements\n * @template U The type of output elements\n * @param fn - Function that maps each element to an iterable\n * @returns A function that flat maps an iterable\n * @example\n * ```typescript\n * const duplicateEach = flatMap((x: number) => [x, x * 2]);\n * Array.from(duplicateEach([1, 2, 3])); // [1, 2, 2, 4, 3, 6]\n * ```\n */\nexport function flatMap<T, U>(\n fn: (value: T) => Iterable<U>,\n): (iterable: Iterable<T>) => IterableIterator<U> {\n return function* (iterable: Iterable<T>): IterableIterator<U> {\n for (const value of iterable) {\n yield* fn(value);\n }\n };\n}\n\n/**\n * Creates a curried function that concatenates multiple iterables sequentially.\n * Returns a function that takes any number of iterables and yields all elements in order.\n *\n * @template T The type of elements\n * @returns A function that concatenates iterables\n * @example\n * ```typescript\n * const concatAll = concat<number>();\n * Array.from(concatAll([1, 2], [3, 4], [5, 6]));\n * // [1, 2, 3, 4, 5, 6]\n * ```\n */\nexport function concat<T>(): (\n ...iterables: Iterable<T>[]\n) => IterableIterator<T> {\n return function* (...iterables: Iterable<T>[]): IterableIterator<T> {\n for (const iterable of iterables) {\n yield* iterable;\n }\n };\n}\n\n/**\n * Creates a curried function that inserts a separator element between each item.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param separator - The element to insert between items\n * @returns A function that intersperses an iterable\n * @example\n * ```typescript\n * const addCommas = intersperse(',');\n * Array.from(addCommas(['a', 'b', 'c']));\n * // ['a', ',', 'b', ',', 'c']\n * ```\n */\nexport function intersperse<T>(\n separator: T,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n let isFirst = true;\n for (const value of iterable) {\n if (!isFirst) {\n yield separator;\n }\n yield value;\n isFirst = false;\n }\n };\n}\n\n/**\n * Creates a curried function that emits all intermediate accumulator values.\n * Like reduce but yields each intermediate result.\n *\n * @template T The type of elements in the iterable\n * @template U The type of the accumulated value\n * @param fn - Function to combine the accumulator with each element\n * @param initial - The initial value for the accumulator\n * @returns A function that scans an iterable\n * @example\n * ```typescript\n * const runningSum = scan((acc: number, x: number) => acc + x, 0);\n * Array.from(runningSum([1, 2, 3, 4]));\n * // [0, 1, 3, 6, 10]\n * ```\n */\nexport function scan<T, U>(\n fn: (accumulator: U, value: T) => U,\n initial: U,\n): (iterable: Iterable<T>) => IterableIterator<U> {\n return function* (iterable: Iterable<T>): IterableIterator<U> {\n let accumulator = initial;\n yield accumulator;\n for (const value of iterable) {\n accumulator = fn(accumulator, value);\n yield accumulator;\n }\n };\n}\n\n/**\n * Creates a curried function that adds index as tuple with each element [index, value].\n * Returns a function that creates tuples pairing each element with its zero-based index.\n *\n * @template T The type of elements\n * @returns A function that enumerates an iterable\n * @example\n * ```typescript\n * const enumerateItems = enumerate<string>();\n * Array.from(enumerateItems(['a', 'b', 'c']));\n * // [[0, 'a'], [1, 'b'], [2, 'c']]\n * ```\n */\nexport function enumerate<T>(): (\n iterable: Iterable<T>,\n) => IterableIterator<[number, T]> {\n return function* (iterable: Iterable<T>): IterableIterator<[number, T]> {\n let index = 0;\n for (const value of iterable) {\n yield [index, value];\n index++;\n }\n };\n}\n\n/**\n * Creates a curried function that reverses the iterator order.\n * Returns a function that takes an iterable and returns an iterable iterator.\n * Warning: This operation buffers all elements in memory and may cause\n * performance issues with large iterables.\n *\n * @template T The type of elements\n * @returns A function that reverses an iterable\n * @example\n * ```typescript\n * const reverseItems = reverse<number>();\n * Array.from(reverseItems([1, 2, 3, 4, 5]));\n * // [5, 4, 3, 2, 1]\n * ```\n */\nexport function reverse<T>(): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n const buffer = Array.from(iterable);\n for (let i = buffer.length - 1; i >= 0; i--) {\n yield buffer[i]!;\n }\n };\n}\n\n/**\n * Sorts elements using default comparison.\n * Numbers are sorted numerically, strings lexicographically.\n * Note: This operation requires buffering all elements in memory.\n *\n * @param iterable - The iterable to sort\n * @returns An iterable iterator with elements sorted\n * @example\n * ```typescript\n * Array.from(sort([3, 1, 4, 1, 5]));\n * // [1, 1, 3, 4, 5]\n * Array.from(sort(['c', 'a', 'b']));\n * // ['a', 'b', 'c']\n * ```\n */\nexport function sort(\n iterable: Iterable<number | string>,\n): IterableIterator<number | string> {\n return (function* (): IterableIterator<number | string> {\n const buffer = Array.from(iterable);\n buffer.sort((a, b) => {\n if (typeof a === \"number\" && typeof b === \"number\") {\n return a - b;\n }\n return String(a).localeCompare(String(b));\n });\n yield* buffer;\n })();\n}\n\n/**\n * Creates a curried function that sorts elements using a custom comparison function.\n * Returns a function that takes an iterable and returns an iterable iterator.\n * Note: This operation requires buffering all elements in memory.\n *\n * @template T The type of elements\n * @param compareFn - Function that compares two elements\n * @returns A function that sorts an iterable\n * @example\n * ```typescript\n * const sortAsc = sortBy((a: number, b: number) => a - b);\n * Array.from(sortAsc([3, 1, 4, 1, 5]));\n * // [1, 1, 3, 4, 5]\n * const sortDesc = sortBy((a: number, b: number) => b - a);\n * Array.from(sortDesc([3, 1, 4, 1, 5]));\n * // [5, 4, 3, 1, 1]\n * ```\n */\nexport function sortBy<T>(\n compareFn: (a: T, b: T) => number,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n const buffer = Array.from(iterable);\n buffer.sort(compareFn);\n yield* buffer;\n };\n}\n\n// Windowing operations\n/**\n * Creates a curried function that creates a sliding window of the specified size.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param size - The size of each window (must be at least 1)\n * @returns A function that creates windows from an iterable\n * @throws {Error} If size is less than 1\n * @example\n * ```typescript\n * const windowThree = window(3);\n * Array.from(windowThree([1, 2, 3, 4, 5]));\n * // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]\n * ```\n */\nexport function window<T>(\n size: number,\n): (iterable: Iterable<T>) => IterableIterator<T[]> {\n validatePositiveInteger(size, \"size\", \"window\");\n\n return function* (iterable: Iterable<T>): IterableIterator<T[]> {\n // Use circular buffer to avoid O(n) shift() operations\n const buffer: T[] = new Array(size);\n let count = 0;\n let index = 0;\n\n for (const value of iterable) {\n buffer[index] = value;\n count++;\n index = (index + 1) % size;\n\n if (count >= size) {\n // Build window array in correct order from circular buffer\n const window = new Array(size);\n for (let i = 0; i < size; i++) {\n window[i] = buffer[(index + i) % size];\n }\n yield window;\n }\n }\n };\n}\n\n/**\n * Creates a curried function that splits elements into chunks of the specified size.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param size - The size of each chunk (must be at least 1)\n * @returns A function that creates chunks from an iterable\n * @throws {Error} If size is less than 1\n * @example\n * ```typescript\n * const chunkTwo = chunk(2);\n * Array.from(chunkTwo([1, 2, 3, 4, 5]));\n * // [[1, 2], [3, 4], [5]]\n * ```\n */\nexport function chunk<T>(\n size: number,\n): (iterable: Iterable<T>) => IterableIterator<T[]> {\n validatePositiveInteger(size, \"size\", \"chunk\");\n\n return function* (iterable: Iterable<T>): IterableIterator<T[]> {\n // Preallocate buffer to avoid dynamic resizing\n let buffer: T[] = new Array(size);\n let bufferIndex = 0;\n\n for (const value of iterable) {\n buffer[bufferIndex++] = value;\n\n if (bufferIndex === size) {\n yield buffer;\n buffer = new Array(size);\n bufferIndex = 0;\n }\n }\n\n if (bufferIndex > 0) {\n // Slice to remove unused preallocated slots\n yield buffer.slice(0, bufferIndex);\n }\n };\n}\n\n/**\n * Creates pairs of consecutive elements from an iterable.\n * Returns an iterable iterator of tuples.\n *\n * @template T The type of elements\n * @param iterable - The iterable to create pairs from\n * @returns An iterable iterator of tuples containing consecutive elements\n * @example\n * ```typescript\n * Array.from(pairwise([1, 2, 3, 4]));\n * // [[1, 2], [2, 3], [3, 4]]\n * ```\n */\nexport function pairwise<T>(iterable: Iterable<T>): IterableIterator<[T, T]> {\n return (function* (): IterableIterator<[T, T]> {\n const windowIter = window<T>(2)(iterable);\n for (const arr of { [Symbol.iterator]: () => windowIter }) {\n yield [arr[0]!, arr[1]!] as [T, T];\n }\n })();\n}\n\n// Grouping operations\n/**\n * Creates a curried function that splits elements into two arrays based on a predicate.\n * Returns a function that takes an iterable and returns a tuple of arrays.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that partitions an iterable\n * @example\n * ```typescript\n * const partitionEvens = partition((x: number) => x % 2 === 0);\n * partitionEvens([1, 2, 3, 4, 5]);\n * // [[2, 4], [1, 3, 5]]\n * ```\n */\nexport function partition<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => [T[], T[]] {\n return function (iterable: Iterable<T>): [T[], T[]] {\n const truthy: T[] = [];\n const falsy: T[] = [];\n\n for (const value of iterable) {\n if (predicate(value)) {\n truthy.push(value);\n } else {\n falsy.push(value);\n }\n }\n\n return [truthy, falsy];\n };\n}\n\n/**\n * Creates a curried function that groups elements by a key function into a Map.\n * Returns a function that takes an iterable and returns a Map.\n *\n * @template T The type of elements\n * @template K The type of the grouping key\n * @param keyFn - Function to extract the grouping key from each element\n * @returns A function that groups an iterable\n * @example\n * ```typescript\n * const groupByLength = groupBy((s: string) => s.length);\n * groupByLength(['alice', 'bob', 'charlie', 'dave']);\n * // Map { 3 => ['bob'], 5 => ['alice'], 7 => ['charlie'], 4 => ['dave'] }\n * ```\n */\nexport function groupBy<T, K>(\n keyFn: (value: T) => K,\n): (iterable: Iterable<T>) => Map<K, T[]> {\n return function (iterable: Iterable<T>): Map<K, T[]> {\n const groups = new Map<K, T[]>();\n\n for (const value of iterable) {\n const key = keyFn(value);\n if (!groups.has(key)) {\n groups.set(key, []);\n }\n groups.get(key)!.push(value);\n }\n\n return groups;\n };\n}\n\n// Set operations\n/**\n * Removes duplicate elements from an iterable, keeping only the first occurrence of each.\n * Uses strict equality (===) to compare elements.\n *\n * @template T The type of elements\n * @param iterable - The iterable to deduplicate\n * @returns An iterable iterator with duplicate elements removed\n * @example\n * ```typescript\n * Array.from(distinct([1, 2, 2, 3, 1, 4]));\n * // [1, 2, 3, 4]\n * ```\n */\nexport function distinct<T>(iterable: Iterable<T>): IterableIterator<T> {\n return (function* (): IterableIterator<T> {\n const seen = new Set<T>();\n\n for (const value of iterable) {\n if (!seen.has(value)) {\n seen.add(value);\n yield value;\n }\n }\n })();\n}\n\n/**\n * Creates a curried function that removes duplicate elements based on a key function.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @template K The type of the key used for comparison\n * @param keyFn - Function to extract the comparison key from each element\n * @returns A function that deduplicates an iterable by key\n * @example\n * ```typescript\n * const users = [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 1, name: 'Charlie'}];\n * const distinctById = distinctBy((u: typeof users[0]) => u.id);\n * Array.from(distinctById(users));\n * // [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}]\n * ```\n */\nexport function distinctBy<T, K>(\n keyFn: (value: T) => K,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n const seenKeys = new Set<K>();\n\n for (const value of iterable) {\n const key = keyFn(value);\n if (!seenKeys.has(key)) {\n seenKeys.add(key);\n yield value;\n }\n }\n };\n}\n\n// Utility operations\n/**\n * Creates a curried function that executes a side-effect function on each element.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param fn - Function to execute for each element\n * @returns A function that taps an iterable\n * @example\n * ```typescript\n * const log = tap((x: number) => console.log('Processing:', x));\n * Array.from(log([1, 2, 3])); // logs each value, returns [1, 2, 3]\n * ```\n */\nexport function tap<T>(\n fn: (value: T) => void,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n for (const value of iterable) {\n fn(value);\n yield value;\n }\n };\n}\n\n/**\n * Creates a curried function that takes elements while the predicate returns true.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that takes elements while predicate is true\n * @example\n * ```typescript\n * const takeLessThanFour = takeWhile((x: number) => x < 4);\n * Array.from(takeLessThanFour([1, 2, 3, 4, 1, 2]));\n * // [1, 2, 3]\n * ```\n */\nexport function takeWhile<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n for (const value of iterable) {\n if (!predicate(value)) break;\n yield value;\n }\n };\n}\n\n/**\n * Creates a curried function that skips elements while the predicate returns true.\n * Returns a function that takes an iterable and returns an iterable iterator.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that drops elements while predicate is true\n * @example\n * ```typescript\n * const dropLessThanThree = dropWhile((x: number) => x < 3);\n * Array.from(dropLessThanThree([1, 2, 3, 4, 1, 2]));\n * // [3, 4, 1, 2]\n * ```\n */\nexport function dropWhile<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => IterableIterator<T> {\n return function* (iterable: Iterable<T>): IterableIterator<T> {\n let dropping = true;\n for (const value of iterable) {\n if (dropping && predicate(value)) {\n continue;\n }\n dropping = false;\n yield value;\n }\n };\n}\n\n// Terminal operations\n/**\n * Collects all elements from an iterable into an array.\n *\n * @template T The type of elements\n * @param iterable - The iterable to convert to an array\n * @returns An array containing all elements\n * @example\n * ```typescript\n * toArray([1, 2, 3]); // [1, 2, 3]\n * ```\n */\nexport function toArray<T>(iterable: Iterable<T>): T[] {\n return Array.from(iterable);\n}\n\n/**\n * Creates a curried function that reduces an iterable to a single value.\n * Returns a function that takes an iterable and returns the reduced value.\n *\n * @template T The type of elements in the iterable\n * @template U The type of the accumulated value\n * @param fn - Function to combine the accumulator with each element\n * @param initial - The initial value for the accumulator\n * @returns A function that reduces an iterable\n * @example\n * ```typescript\n * const sumAll = reduce((acc: number, x: number) => acc + x, 0);\n * sumAll([1, 2, 3, 4]); // 10\n * const concat = reduce((acc: string, x: string) => acc + x, '');\n * concat(['a', 'b', 'c']); // 'abc'\n * ```\n */\nexport function reduce<T, U>(\n fn: (accumulator: U, value: T) => U,\n initial: U,\n): (iterable: Iterable<T>) => U {\n return function (iterable: Iterable<T>): U {\n let accumulator = initial;\n for (const value of iterable) {\n accumulator = fn(accumulator, value);\n }\n return accumulator;\n };\n}\n\n/**\n * Creates a curried function that finds the first element matching a predicate.\n * Returns a function that takes an iterable and returns the first matching element or undefined.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that finds an element in an iterable\n * @example\n * ```typescript\n * const findGreaterThanThree = find((x: number) => x > 3);\n * findGreaterThanThree([1, 2, 3, 4, 5]); // 4\n * findGreaterThanThree([1, 2, 3]); // undefined\n * ```\n */\nexport function find<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => T | undefined {\n return function (iterable: Iterable<T>): T | undefined {\n for (const value of iterable) {\n if (predicate(value)) {\n return value;\n }\n }\n return undefined;\n };\n}\n\n/**\n * Creates a curried function that finds the index of the first element matching a predicate.\n * Returns a function that takes an iterable and returns the index or -1.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that finds an index in an iterable\n * @example\n * ```typescript\n * const findIndexGreaterThanThree = findIndex((x: number) => x > 3);\n * findIndexGreaterThanThree([1, 2, 3, 4, 5]); // 3\n * findIndexGreaterThanThree([1, 2, 3]); // -1\n * ```\n */\nexport function findIndex<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => number {\n return function (iterable: Iterable<T>): number {\n let index = 0;\n for (const value of iterable) {\n if (predicate(value)) {\n return index;\n }\n index++;\n }\n return -1;\n };\n}\n\n/**\n * Creates a curried function that tests if any element matches a predicate.\n * Returns a function that takes an iterable and returns a boolean.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that tests an iterable\n * @example\n * ```typescript\n * const hasGreaterThanThree = some((x: number) => x > 3);\n * hasGreaterThanThree([1, 2, 3, 4, 5]); // true\n * hasGreaterThanThree([1, 2, 3]); // false\n * ```\n */\nexport function some<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => boolean {\n return function (iterable: Iterable<T>): boolean {\n for (const value of iterable) {\n if (predicate(value)) {\n return true;\n }\n }\n return false;\n };\n}\n\n/**\n * Creates a curried function that tests if all elements match a predicate.\n * Returns a function that takes an iterable and returns a boolean.\n *\n * @template T The type of elements\n * @param predicate - Function to test each element\n * @returns A function that tests an iterable\n * @example\n * ```typescript\n * const allEven = every((x: number) => x % 2 === 0);\n * allEven([2, 4, 6]); // true\n * allEven([1, 2, 3]); // false\n * ```\n */\nexport function every<T>(\n predicate: (value: T) => boolean,\n): (iterable: Iterable<T>) => boolean {\n return function (iterable: Iterable<T>): boolean {\n for (const value of iterable) {\n if (!predicate(value)) {\n return false;\n }\n }\n return true;\n };\n}\n\n/**\n * Gets the first element from an iterable.\n *\n * @template T The type of elements\n * @param iterable - The iterable to get the first element from\n * @param defaultValue - Optional default value to return if iterable is empty\n * @returns The first element, the default value, or undefined if empty and no default\n * @example\n * ```typescript\n * first([1, 2, 3]); // 1\n * first([]); // undefined\n * first([], 0); // 0\n * ```\n */\nexport function first<T>(\n iterable: Iterable<T>,\n defaultValue?: T,\n): T | undefined {\n const iterator = iterable[Symbol.iterator]();\n const result = iterator.next();\n return result.done ? defaultValue : result.value;\n}\n\n/**\n * Gets the last element from an iterable.\n *\n * @template T The type of elements\n * @param iterable - The iterable to get the last element from\n * @param defaultValue - Optional default value to return if iterable is empty\n * @returns The last element, the default value, or undefined if empty and no default\n * @example\n * ```typescript\n * last([1, 2, 3]); // 3\n * last([]); // undefined\n * last([], 0); // 0\n * ```\n */\nexport function last<T>(\n iterable: Iterable<T>,\n defaultValue?: T,\n): T | undefined {\n let lastValue: T | undefined = defaultValue;\n let hasValue = false;\n for (const value of iterable) {\n lastValue = value;\n hasValue = true;\n }\n return hasValue ? lastValue : defaultValue;\n}\n\n/**\n * Creates a curried function that gets the element at a specified index.\n * Returns a function that takes an iterable and returns the element or undefined.\n *\n * @template T The type of elements\n * @param index - Zero-based index of the element to retrieve\n * @returns A function that gets an element from an iterable\n * @example\n * ```typescript\n * const getSecond = nth(2);\n * getSecond([1, 2, 3, 4, 5]); // 3\n * getSecond([1, 2]); // undefined\n * nth(-1)([1, 2, 3]); // undefined\n * ```\n */\nexport function nth<T>(\n index: number,\n): (iterable: Iterable<T>) => T | undefined {\n return function (iterable: Iterable<T>): T | undefined {\n if (index < 0) {\n return undefined;\n }\n let currentIndex = 0;\n for (const value of iterable) {\n if (currentIndex === index) {\n return value;\n }\n currentIndex++;\n }\n return undefined;\n };\n}\n\n/**\n * Checks if an iterable is empty.\n *\n * @template T The type of elements\n * @param iterable - The iterable to check\n * @returns true if the iterable has no elements, false otherwise\n * @example\n * ```typescript\n * isEmpty([]); // true\n * isEmpty([1, 2, 3]); // false\n * ```\n */\nexport function isEmpty<T>(iterable: Iterable<T>): boolean {\n const iterator = iterable[Symbol.iterator]();\n const result = iterator.next();\n return result.done === true;\n}\n\n/**\n * Creates a curried function that checks if an iterable includes a specific value.\n * Uses strict equality (===) for comparison.\n * Returns a function that takes an iterable and returns a boolean.\n *\n * @template T The type of elements\n * @param searchValue - The value to search for\n * @returns A function that checks if an iterable includes the value\n * @example\n * ```typescript\n * const includesThree = includes(3);\n * includesThree([1, 2, 3, 4, 5]); // true\n * includesThree([1, 2, 4]); // false\n * includes('b')(['a', 'b', 'c']); // true\n * ```\n */\nexport function includes<T>(\n searchValue: T,\n): (iterable: Iterable<T>) => boolean {\n return function (iterable: Iterable<T>): boolean {\n for (const value of iterable) {\n if (value === searchValue) {\n return true;\n }\n }\n return false;\n };\n}\n\n// Combining operations\n/**\n * Combines two iterables into an iterator of tuples.\n * Stops when the shorter iterable is exhausted.\n *\n * @template T The type of elements in the first iterable\n * @template U The type of elements in the second iterable\n * @param iter1 - The first iterable\n * @param iter2 - The second iterable\n * @returns An iterable iterator of tuples pairing elements from both iterables\n * @example\n * ```typescript\n * Array.from(zip([1, 2, 3], ['a', 'b', 'c']));\n * // [[1, 'a'], [2, 'b'], [3, 'c']]\n * ```\n */\nexport function zip<T, U>(\n iter1: Iterable<T>,\n iter2: Iterable<U>,\n): IterableIterator<[T, U]> {\n return (function* (): IterableIterator<[T, U]> {\n const it1 = iter1[Symbol.iterator]();\n const it2 = iter2[Symbol.iterator]();\n\n while (true) {\n const result1 = it1.next();\n const result2 = it2.next();\n\n if (result1.done || result2.done) {\n break;\n }\n\n yield [result1.value, result2.value];\n }\n })();\n}\n\n/**\n * Combines two iterables using a combining function.\n * Stops when the shorter iterable is exhausted.\n *\n * @template T The type of elements in the first iterable\n * @template U The type of elements in the second iterable\n * @template R The type of the result\n * @param iter1 - The first iterable\n * @param iter2 - The second iterable\n * @param fn - Function to combine elements from both iterables\n * @returns An iterable iterator with combined results\n * @example\n * ```typescript\n * Array.from(zipWith([1, 2, 3], [10, 20, 30], (a, b) => a + b));\n * // [11, 22, 33]\n * ```\n */\nexport function zipWith<T, U, R>(\n iter1: Iterable<T>,\n iter2: Iterable<U>,\n fn: (a: T, b: U) => R,\n): IterableIterator<R> {\n return (function* (): IterableIterator<R> {\n const zipIter = zip(iter1, iter2);\n for (const [a, b] of { [Symbol.iterator]: () => zipIter }) {\n yield fn(a, b);\n }\n })();\n}\n\n// Generator functions\n/**\n * Generates a sequence of numbers.\n * Supports three call signatures:\n * - range(stop): generates [0, stop) with step 1\n * - range(start, stop): generates [start, stop) with step 1\n * - range(start, stop, step): generates [start, stop) with custom step\n *\n * @param stop - The end value (exclusive) when called with one argument\n * @returns An iterable iterator of numbers\n * @throws {Error} If step is zero\n * @example\n * ```typescript\n * Array.from(range(5)); // [0, 1, 2, 3, 4]\n * Array.from(range(2, 5)); // [2, 3, 4]\n * Array.from(range(0, 10, 2)); // [0, 2, 4, 6, 8]\n * Array.from(range(5, 0, -1)); // [5, 4, 3, 2, 1]\n * ```\n */\nexport function range(stop: number): IterableIterator<number>;\n/**\n * Generates a sequence of numbers from start to stop (exclusive).\n *\n * @param start - The starting value (inclusive)\n * @param stop - The end value (exclusive)\n * @returns An iterable iterator of numbers\n */\nexport function range(start: number, stop: number): IterableIterator<number>;\n/**\n * Generates a sequence of numbers from start to stop (exclusive) with a custom step.\n *\n * @param start - The starting value (inclusive)\n * @param stop - The end value (exclusive)\n * @param step - The increment between values\n * @returns An iterable iterator of numbers\n */\nexport function range(\n start: number,\n stop: number,\n step: number,\n): IterableIterator<number>;\nexport function range(\n startOrStop: number,\n stop?: number,\n step = 1,\n): IterableIterator<number> {\n const actualStart = stop === undefined ? 0 : startOrStop;\n const actualStop = stop === undefined ? startOrStop : stop;\n\n return (function* (): IterableIterator<number> {\n validateNonZero(step, \"step\", \"range\");\n\n if (step > 0) {\n for (let i = actualStart; i < actualStop; i += step) {\n yield i;\n }\n } else {\n for (let i = actualStart; i > actualStop; i += step) {\n yield i;\n }\n }\n })();\n}\n\n/**\n * Repeats a value a specified number of times, or infinitely.\n * If times is not specified, creates an infinite iterator.\n *\n * @template T The type of the value to repeat\n * @param value - The value to repeat\n * @param times - Optional number of times to repeat (infinite if omitted)\n * @returns An iterable iterator repeating the value\n * @example\n * ```typescript\n * Array.from(repeat('x', 3)); // ['x', 'x', 'x']\n * Array.from(repeat(0, 5)); // [0, 0, 0, 0, 0]\n * Array.from(take(3)(repeat(1))); // [1, 1, 1] (infinite, limited by take)\n * ```\n */\nexport function repeat<T>(value: T, times?: number): IterableIterator<T> {\n return (function* (): IterableIterator<T> {\n if (times === undefined) {\n while (true) {\n yield value;\n }\n } else {\n for (let i = 0; i < times; i++) {\n yield value;\n }\n }\n })();\n}\n\n// Interleaving operations\n/**\n * Alternates elements from multiple iterables in a round-robin fashion.\n * Continues until all iterables are exhausted.\n *\n * @template T The type of elements in all iterables\n * @param iterables - Variable number of iterables to interleave\n * @returns An iterable iterator with elements from all iterables interleaved\n * @example\n * ```typescript\n * Array.from(interleave([1, 2, 3], [4, 5, 6]));\n * // [1, 4, 2, 5, 3, 6]\n * Array.from(interleave([1, 2], [3, 4, 5], [6]));\n * // [1, 3, 6, 2, 4, 5]\n * ```\n */\nexport function interleave<T>(\n ...iterables: Iterable<T>[]\n): IterableIterator<T> {\n return (function* (): IterableIterator<T> {\n if (iterables.length === 0) return;\n\n const iterators = iterables.map((it) => it[Symbol.iterator]());\n const active = new Set(iterators);\n\n while (active.size > 0) {\n for (const iterator of iterators) {\n if (!active.has(iterator)) continue;\n\n const result = iterator.next();\n if (result.done) {\n active.delete(iterator);\n } else {\n yield result.value;\n }\n }\n }\n })();\n}\n\n/**\n * Merges multiple sorted iterables into a single sorted iterator.\n * Assumes input iterables are already sorted in ascending order.\n * Uses a custom comparator if provided, otherwise uses default < comparison.\n *\n * @template T The type of elements in all iterables\n * @param iterables - Variable number of sorted iterables to merge\n * @returns An iterable iterator with all elements merged in sorted order\n * @example\n * ```typescript\n * Array.from(merge([1, 3, 5], [2, 4, 6]));\n * // [1, 2, 3, 4, 5, 6]\n * Array.from(merge([1, 5, 9], [2, 6, 10], [3, 7, 11]));\n * // [1, 2, 3, 5, 6, 7, 9, 10, 11]\n * ```\n */\nexport function merge<T>(...iterables: Iterable<T>[]): IterableIterator<T>;\nexport function merge<T>(\n compareFn: (a: T, b: T) => number,\n ...iterables: Iterable<T>[]\n): IterableIterator<T>;\nexport function merge<T>(\n ...args: (Iterable<T> | ((a: T, b: T) => number))[]\n): IterableIterator<T> {\n let compareFn: (a: T, b: T) => number;\n let iterables: Iterable<T>[];\n\n // Check if first argument is a function (comparator)\n if (typeof args[0] === \"function\") {\n compareFn = args[0] as (a: T, b: T) => number;\n iterables = args.slice(1) as Iterable<T>[];\n } else {\n // Default comparator for numbers/strings\n compareFn = (a: T, b: T) => {\n if (a < b) return -1;\n if (a > b) return 1;\n return 0;\n };\n iterables = args as Iterable<T>[];\n }\n\n return (function* (): IterableIterator<T> {\n if (iterables.length === 0) return;\n\n // Initialize all iterators with their first value\n const heap: Array<{\n value: T;\n iterator: Iterator<T>;\n index: number;\n }> = [];\n\n for (let i = 0; i < iterables.length; i++) {\n const iterator = iterables[i]![Symbol.iterator]();\n const result = iterator.next();\n if (!result.done) {\n heap.push({ value: result.value, iterator, index: i });\n }\n }\n\n // Helper to maintain min-heap property\n const bubbleDown = (index: number) => {\n const length = heap.length;\n while (true) {\n let smallest = index;\n const leftChild = 2 * index + 1;\n const rightChild = 2 * index + 2;\n\n if (\n leftChild < length &&\n compareFn(heap[leftChild]!.value, heap[smallest]!.value) < 0\n ) {\n smallest = leftChild;\n }\n\n if (\n rightChild < length &&\n compareFn(heap[rightChild]!.value, heap[smallest]!.value) < 0\n ) {\n smallest = rightChild;\n }\n\n if (smallest === index) break;\n\n [heap[index], heap[smallest]] = [heap[smallest]!, heap[index]!];\n index = smallest;\n }\n };\n\n // Build initial heap\n for (let i = Math.floor(heap.length / 2) - 1; i >= 0; i--) {\n bubbleDown(i);\n }\n\n // Extract minimum and refill from same iterator\n while (heap.length > 0) {\n const { value, iterator } = heap[0]!;\n yield value;\n\n const result = iterator.next();\n if (result.done) {\n // Remove this iterator from heap\n heap[0] = heap[heap.length - 1]!;\n heap.pop();\n if (heap.length > 0) {\n bubbleDown(0);\n }\n } else {\n // Replace with next value from same iterator\n heap[0]!.value = result.value;\n bubbleDown(0);\n }\n }\n })();\n}\n\n/**\n * Chains multiple iterables sequentially, one after another.\n * Yields all elements from the first iterable, then all from the second, etc.\n *\n * @template T The type of elements in all iterables\n * @param iterables - Variable number of iterables to chain\n * @returns An iterable iterator with all elements chained sequentially\n * @example\n * ```typescript\n * Array.from(chain([1, 2], [3, 4], [5, 6]));\n * // [1, 2, 3, 4, 5, 6]\n * Array.from(chain([1], [2, 3], [], [4, 5, 6]));\n * // [1, 2, 3, 4, 5, 6]\n * ```\n */\nexport function chain<T>(...iterables: Iterable<T>[]): IterableIterator<T> {\n return (function* (): IterableIterator<T> {\n for (const iterable of iterables) {\n yield* iterable;\n }\n })();\n}\n\n// Composition utilities\nexport {\n pipe,\n compose,\n createOperation,\n // Transducers\n mapTransducer,\n filterTransducer,\n takeTransducer,\n composeTransducers,\n transduce,\n transducerToIterator,\n reduced,\n isReduced,\n // Types\n type IterableTransformer,\n type TerminalOperation,\n type Transducer,\n type Reducer,\n} from \"./composition.js\";\n"]}
|