import type { array } from "./arrays.ts"; import type { domainOf } from "./domain.ts"; import type { andPreserveUnknown } from "./generics.ts"; import type { Hkt } from "./hkt.ts"; import type { propValueOf, requiredKeyOf } from "./records.ts"; export interface AndPreserveUnknown extends Hkt<[unknown, unknown]> { body: andPreserveUnknown; } type SequenceIntersectionKind = "array" | "parameters"; export type intersectArrays = intersectSequences; export type intersectParameters = intersectSequences; type intersectSequences = l extends readonly [] ? kind extends "array" ? [ ] extends r ? [ ...acc, ...postfix ] : never : [...acc, ...r, ...postfix] : r extends readonly [] ? kind extends "array" ? [ ] extends l ? [ ...acc, ...postfix ] : never : [...acc, ...l, ...postfix] : [ l, r ] extends ([ readonly [(infer lHead)?, ...infer lTail], readonly [(infer rHead)?, ...infer rTail] ]) ? [ "0", lHead, rHead ] extends [keyof l | keyof r, l[0], r[0]] ? intersectSequences? ] : [...acc, Hkt.apply], postfix, operation, kind> : l extends readonly [...infer lInit, infer lLast] ? r extends readonly [...infer rInit, infer rLast] ? intersectSequences, ...postfix ], operation, kind> : intersectSequences, ...postfix ], operation, kind> : r extends readonly [...infer rInit, infer rLast] ? intersectSequences, ...postfix ], operation, kind> : [...acc, ...Hkt.apply[], ...postfix] : never; export type isDisjoint = overlaps extends true ? false : true; export type overlaps = l & r extends never ? false : domainOf & domainOf extends never ? false : [l, r] extends [object, object] ? false extends (propValueOf<{ [k in Extract | requiredKeyOf>]: overlaps; }>) ? false : true : true; export {};