import {joinTypes, typeOfDependency, Dependency} from '../core/Dispatcher.js' export type Complex = {re: T; im: T;} export const Complex_type = { test: (dep: {testT: (z: unknown) => z is T}) => (z: unknown): z is Complex => typeof z === 'object' && 're' in z && 'im' in z && dep.testT(z.re) && dep.testT(z.im), infer: (dep: typeOfDependency) => (z: Complex) => joinTypes(dep.typeOf(z.re), dep.typeOf(z.im)), from: { T: (dep: Dependency<'zero', [T]>) => (t: T) => ({re: t, im: dep.zero(t)}), Complex: (dep: {convert: (from: U) => T}) => (z: Complex) => ({re: dep.convert(z.re), im: dep.convert(z.im)}) } } export const complex_unary = (dep: Dependency<'zero', [T]>) => (t: T) => ({re: t, im: dep.zero(t)}) export const complex_binary = (t: T, u: T) => ({re: t, im: u})