ММ
Size: a a a
ММ
VF
AW
const ArrayTypeID = Symbol('Array');
type ArrayTypeID = typeof ArrayTypeID;
const TreeTypeID = Symbol('Tree');
type TreeTypeID = typeof TreeTypeID;
interface Tree<T> {
value: T,
children: Tree<T>[],
}
interface IDs<A> {
readonly [ArrayTypeID]: Array<A>
readonly [TreeTypeID]: Tree<A>
}
type TypeIds = keyof IDs<any>;
type Type<Container extends TypeIds, Element> = IDs<Element>[Container];
type X = Type<TreeTypeID, number>
type A<Id extends TypeIds, E> = (input: Type<Id, E>) => E;
const reduceTree: A<TreeTypeID, number> = (a: Tree<number>) => a.value;
type Reducer<T extends TypeIds, U> = {
reduce: (input: Type<T, U>) => U
}
const reduceOp = <T extends TypeIds, U>(r: Reducer<T, U>) => (input: Type<T,U>) => r.reduce(input)
const ArrayNumberReducer: Reducer<ArrayTypeID, number> = {
reduce(a) {
return a.reduce((a,b) => a + b);
}
}
const res = reduceOp(ArrayNumberReducer)([1,2,3])AW
VF
AW
VF
AW
VF
VF
VF
AW
AW
AW
ММ
VF
AW
VF
ii
AW