// ets_tracing: off import "../Operator/index.js" import type { Tuple } from "../Collections/Immutable/Tuple/index.js" import type { _A, _E, _R } from "../Effect/index.js" import type { Either } from "../Either/core.js" import type { Tag } from "../Has/index.js" import type { Option } from "../Option/index.js" import { none, some } from "../Option/index.js" import type { Sync } from "../Sync/index.js" export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ( k: infer I ) => void ? I : never export type EnforceNonEmptyRecord = keyof R extends never ? never : R export function intersect( ...as: AS ): UnionToIntersection<{ [k in keyof AS]: AS[k] }[number]> { return as.reduce((a: any, b: any) => ({ ...a, ...b })) as any } export const pattern: ( n: N ) => { < X extends { [k in N]: string }, K extends { [k in X[N]]: ( _: Extract, __: Extract ) => any } >( _: K ): (m: X) => ReturnType < X extends { [k in N]: string }, K extends Partial<{ [k in X[N]]: ( _: Extract, __: Extract ) => any }>, H >( _: K & { [k in X[N]]?: ( _: Extract, __: Extract ) => any }, __: (_: Exclude, __: Exclude) => H ): (m: X) => { [k in keyof K]: ReturnType> }[keyof K] | H } = (n) => ((_: any, d: any) => (m: any) => { return (_[m[n]] ? _[m[n]](m, m) : d(m, m)) as any }) as any export const matchTag = pattern("_tag") export const pattern_: ( n: N ) => { < X extends { [k in N]: string }, K extends { [k in X[N]]: ( _: Extract, __: Extract ) => any } >( m: X, _: K ): ReturnType < X extends { [k in N]: string }, K extends Partial<{ [k in X[N]]: ( _: Extract, __: Extract ) => any }>, H >( m: X, _: K & { [k in X[N]]?: ( _: Extract, __: Extract ) => any }, __: (_: Exclude, __: Exclude) => H ): { [k in keyof K]: ReturnType> }[keyof K] | H } = (n) => ((m: any, _: any, d: any) => { return (_[m[n]] ? _[m[n]](m, m) : d(m, m)) as any }) as any export const matchTag_ = pattern_("_tag") export const patternFor: ( n: N ) => () => { < K extends { [k in X[N]]: ( _: Extract, __: Extract ) => any } >( _: K ): (m: X) => ReturnType < K extends Partial<{ [k in X[N]]: ( _: Extract, __: Extract ) => any }>, H >( _: K & { [k in X[N]]?: ( _: Extract, __: Extract ) => any }, __: (_: Exclude, __: Exclude) => H ): (m: X) => { [k in keyof K]: ReturnType> }[keyof K] | H } = (n) => () => ((_: any, d: any) => (m: any) => { return (_[m[n]] ? _[m[n]](m, m) : d(m, m)) as any }) as any export const matchTagFor = patternFor("_tag") export type RefinementWithIndex = (i: I, a: A) => a is B export type PredicateWithIndex = (i: I, a: A) => boolean export type Erase = R & K extends K & infer R1 ? R1 : R export type _A = [T] extends [{ [k in typeof _A]: () => infer A }] ? A : never export type _R = [T] extends [{ [k in typeof _R]: (_: infer R) => void }] ? R : never export type _E = [T] extends [{ [k in typeof _E]: () => infer E }] ? E : never export * from "./tool.js" export function isEither(u: unknown): u is Either { return ( typeof u === "object" && u != null && "_tag" in u && (u["_tag"] === "Left" || u["_tag"] === "Right") ) } export function isOption(u: unknown): u is Option { return ( typeof u === "object" && u != null && "_tag" in u && (u["_tag"] === "Some" || u["_tag"] === "None") ) } export function isTag(u: unknown): u is Tag { return typeof u === "object" && u != null && "_tag" in u && u["_tag"] === "Tag" } export function isSync(u: unknown): u is Sync { return typeof u === "object" && u != null && "_tag" in u && u["_tag"] === "XPure" } export function isAdtElement( tag: K ): (adt: A) => adt is Extract { return (adt: A): adt is Extract => adt["_tag"] === tag } export function isGenericAdtElement( _t: T ): ( tag: K ) => (adt: A) => adt is Extract { return (tag: K) => (adt: A): adt is Extract => adt[_t] === tag } export function onAdtElement( tag: K, f: (_: Extract) => B ): (adt: A) => Option { return (adt: A) => { if (adt["_tag"] === tag) { return some(f(adt as any)) } return none } } export function onGenericAdtElement(_t: T) { return ( tag: K, f: (_: Extract) => B ) => (adt: A): Option => { if (adt[_t] === tag) { return some(f(adt as any)) } return none } } export type ForcedTuple = A extends unknown[] ? Tuple : never export type ForcedArray = A extends readonly any[] ? A : [] export interface UnifiableIndexed {} export * from "./lazy.js" export * from "./union.js" export * from "./equal.js" export * from "./unification.js"