import type { Ary } from "."; import type { Args, Fn } from "../HKT"; import type IsNatFn from "../Num/Nat/IsNat"; import type { Filter } from "../Union/Filter"; import type { If, IsAny, IsNever, Not } from "../helpers"; /** * Check if an {@link Ary} (i.e., `Array` or `ReadonlyArray`) is a tuple. * * Sig: `(a: Ary) => boolean` * * @example * ```typescript * type R1 = IsTuple; * // ^?: false * type R2 = IsTuple; * // ^?: false * type R3 = IsTuple<["foo", "bar"]>; * // ^?: true * type R4 = IsTuple; * // ^?: true * type R6 = IsTuple; * // ^?: false, because `readonly [...string[]]` is actually equal to `readonly string[]`, and * // the same is true for something like `[...(number | string)[]]`, which is equal to * // `(number | string)[]`, etc. * type R7 = IsTuple<[]>; * // ^?: true * ``` */ export type IsTuple = If< IsAny, boolean, A extends A ? A["length"] extends 0 ? true : Not>>> : never >; /** * [Fn] Check if an {@link Ary} (i.e., `Array` or `ReadonlyArray`) is a tuple. * * Sig: `(a: Ary) => boolean` */ export default interface IsTupleFn extends Fn<[Ary], boolean> { def: ([a]: Args) => IsTuple; }