import { List } from '../List' ; import { ApKind , ofAp } from './ap' ; import { IsUnion } from './do' ; import { HKT , ReplaceFirst , Type , URIS , of , ReplaceFirstAndReplaceSecondIfSecondIsNever } from './hkt' ; export const sequenceT = < Of extends ofAp < any > > ( of ) => < Ap extends ApKind < any , any [ ] > = ReturnType < Of > , T extends Array < ApKind < Ap [ '_URI' ] , any > > = any , Rest extends any [ ] = T [ number ] [ '_A' ] extends [ infer _Head , ... infer Rest ] ? Rest : never > ( ... t ) : IsUnion < Rest > extends true ? [ 'ERROR: All secondary generics must be of the same type. Different generics found: ' , Rest [ number ] ] : Type < Ap [ '_URI' ] , ReplaceFirst < T extends never ? [ ] : T [ number ] [ '_A' ] , { [ K in keyof T ] : T [ K ] extends ApKind < any , infer A > ? A [ 0 ] : never ; } > > => { return List ( t as any ) . sequence ( of ) as any ; } ; export const sequenceTFlex = < Of extends ofAp < any > > ( of ) => < Ap extends ApKind < any , any > = ReturnType < Of > , T extends Array < ApKind < Ap [ '_URI' ] , any > > = any > ( ... t ) : Type < Ap [ '_URI' ] , ReplaceFirst < T [ number ] [ '_A' ] , { [ K in keyof T ] : T [ K ] extends ApKind < any , infer A > ? A [ 0 ] : never ; } > > => { return List ( t as T ) . sequence ( of ) ; } ;