import { Adt } from '@ephox/katamari'; type DirectionFunc = () => T; export interface DirectionAdt { fold: ( southeast: DirectionFunc, southwest: DirectionFunc, northeast: DirectionFunc, northwest: DirectionFunc, south: DirectionFunc, north: DirectionFunc, east: DirectionFunc, west: DirectionFunc, ) => T; match: (branches: { southeast: DirectionFunc; southwest: DirectionFunc; northeast: DirectionFunc; northwest: DirectionFunc; south: DirectionFunc; north: DirectionFunc; east: DirectionFunc; west: DirectionFunc; }) => T; log: (label: string) => void; } const adt: { southeast: DirectionFunc; southwest: DirectionFunc; northeast: DirectionFunc; northwest: DirectionFunc; south: DirectionFunc; north: DirectionFunc; east: DirectionFunc; west: DirectionFunc; } = Adt.generate([ { southeast: [ ] }, { southwest: [ ] }, { northeast: [ ] }, { northwest: [ ] }, { south: [ ] }, { north: [ ] }, { east: [ ] }, { west: [ ] } ]); const cata = ( subject: DirectionAdt, southeast: DirectionFunc, southwest: DirectionFunc, northeast: DirectionFunc, northwest: DirectionFunc, south: DirectionFunc, north: DirectionFunc, east: DirectionFunc, west: DirectionFunc ): B => subject.fold(southeast, southwest, northeast, northwest, south, north, east, west); const cataVertical = (subject: DirectionAdt, south: DirectionFunc, middle: DirectionFunc, north: DirectionFunc): B => subject.fold(south, south, north, north, south, north, middle, middle); const cataHorizontal = (subject: DirectionAdt, east: DirectionFunc, middle: DirectionFunc, west: DirectionFunc): B => subject.fold(east, west, east, west, middle, middle, east, west); // TODO: Simplify with the typescript approach. const southeast = adt.southeast; const southwest = adt.southwest; const northeast = adt.northeast; const northwest = adt.northwest; const south = adt.south; const north = adt.north; const east = adt.east; const west = adt.west; export { southeast, southwest, northeast, northwest, south, north, east, west, cata, cataVertical, cataHorizontal };