34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import {Specifications, joinTypes, typeOfDependency} from '../core/Dispatcher'
|
|
|
|
export type Complex<T> = {re: T; im: T;}
|
|
|
|
declare module 'Dispatcher' {
|
|
namespace Specifications {
|
|
export class ComplexSpecifications {}
|
|
|
|
namespace ComplexSpecifications {
|
|
export class Complex_type<T> {
|
|
static test = (testT: (z: unknown) => z is T) =>
|
|
(z: unknown): z is Complex<T> =>
|
|
typeof z === 'object'
|
|
&& 're' in z && 'im' in z
|
|
&& testT(z.re) && testT(z.im);
|
|
static infer = (dep: typeOfDependency) =>
|
|
(z: Complex<unknown>) =>
|
|
joinTypes(dep.typeOf(z.re), dep.typeOf(z.im));
|
|
static from = {
|
|
T: (dep: ImplementationType<'zero', [T]>) => (t: T) =>
|
|
({re: t, im: dep.zero(t)}),
|
|
Complex: <U>(convert: (from: U) => T) =>
|
|
(z: Complex<U>) => ({re: convert(z.re), im: convert(z.im)})
|
|
};
|
|
}
|
|
export const complex_1 = <T>(dep: DependencyType<'zero', [T]>) =>
|
|
(t: T) => ({re: t, im: dep.zero(t)})
|
|
export const complex_2 = <T>(t: T, u: T) => ({re: t, im: u})
|
|
}
|
|
}
|
|
}
|
|
|
|
export {Specifications}
|