Skip to content

Commit

Permalink
2024/01/13 - First ugly implementation of previous/next of arbitrary …
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
FadiShawki committed Jan 13, 2024
1 parent abcbd03 commit 15ac009
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 39 deletions.
32 changes: 29 additions & 3 deletions src/@orbitmines/explorer/Ray.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,50 @@ describe("Ray", () => {
expect(method(a)(b).terminal.self.any.js).toBe('B');
expect(method(a)(b).type).toBe(RayType.VERTEX);
});
test(".next", () => {
test("[A, B, C][.next, .previous]", () => {
const A = Ray.vertex().o({ js: 'A' }).as_reference().o({ js: 'A.#' });
const B = Ray.vertex().o({ js: 'B'}).as_reference().o({ js: 'B.#' });
const C = Ray.vertex().o({ js: 'C'}).as_reference().o({ js: 'C.#' });
const B = Ray.vertex().o({ js: 'B' }).as_reference().o({ js: 'B.#' });
const C = Ray.vertex().o({ js: 'C' }).as_reference().o({ js: 'C.#' });

let current = A;

expect(() => current.next).toThrow(); // TODO: Should be empty..
expect(() => current.previous).toThrow(); // TODO: Should be empty..

A.continues_with(B).continues_with(C);

expect(() => current.previous).toThrow(); // TODO: Should be ??..
expect(() => current.next.next.next).toThrow(); // TODO: Should be ??..

expect(current.next.type).toBe(RayType.VERTEX);
// expect(current.next.any.js).toBe('B.#'); TODO, maybe the ref??
expect(current.next.self.any.js).toBe('B');

expect(current.next.next.type).toBe(RayType.VERTEX);
expect(current.next.next.self.any.js).toBe('C');

expect(current.next.previous.self.any.js).toBe('A');
expect(current.next.next.previous.self.any.js).toBe('B');
expect(current.next.next.previous.previous.self.any.js).toBe('A');
});
// test(".next(ref => .continues_with(.vertex.#))", () => {
// let A = Ray.vertex().o({ js: 'A' }).as_reference();
// let B = Ray.vertex().o({ js: 'B'}).as_reference();
//
// B = A.next(ref => ref.continues_with(B))
//
// expect(B.type).toBe(RayType.VERTEX);
// expect(B.self.any.js).toBe('B');
// expect(B.self
// .initial.self.initial
// .any.js
// ).toBe('A');
// expect(B.self
// .initial.self.initial
// .terminal.self.terminal
// .any.js
// ).toBe('B');
// });
test(".vertex.#.equivalent(.vertex.#)", () => {
let A = Ray.vertex().o({js: 'A'})
.as_reference().o({js: 'A.#'});
Expand Down
102 changes: 66 additions & 36 deletions src/@orbitmines/explorer/Ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
* previous = (): Option<Ray> => JS.Iterable(this.traverse({ steps: 1, direction: { reverse: true } })).as_ray();
*/
// TODO: These necessarily rever to something which allows you to ask the question of 'next' again. It could return many values (initial/terminal?), a single one: vertex; on which again more structure like a list or something could be defined...
get previous(): Ray { throw new NotImplementedError(); }
get previous(): Ray { return Ray.___next(ref => ref.self.initial.as_reference())(this); }
// TODO: Could remove this as_reference... :thinking:

/**
*
Expand All @@ -421,45 +422,74 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
const method = Ray.___func(ref => {
const { initial, terminal } = ref.self;

// const direction = terminal.type;

// throw new NotImplementedError(`'${direction}'`);

return initial.switch({
[RayType.VERTEX]: () => terminal.switch({

// Many possible continuations
[RayType.VERTEX]: () => {
throw new NotImplementedError()
},

// No continuations, either a self-reference, or different ways of halting.
[RayType.TERMINAL]: () => Ray.None(),

// A possible continuation
[RayType.INITIAL]: (ref) =>
direction(ref).as_reference() // TODO Why is this reference needed?
.switch({ // TODO: This is applying the function again, should be separate?
// Found a next Vertex.
[RayType.VERTEX]: (self) => self,
// [RayType.VERTEX]: (self) => { throw new NotImplementedError(); },

// TODO: Same, but defined a step further
// [RayType.TERMINAL]: () => Ray.None(),
[RayType.TERMINAL]: () => { throw new NotImplementedError(); },

// TODO: This switch could repeat infinitely, we need a way to hook into each step..
[RayType.INITIAL]: () => { throw new NotImplementedError(); },

// TODO: Similar to Initial, probably follow the reference, possibly infintely...
[RayType.REFERENCE]: (ref) => {
// throw new NotImplementedError(`${ref.type}/${ref.self.type} - ${ref.any.js}/${ref.self.any.js}`);
//
// if (ref.self.type === RayType.VERTEX)
// return ref.self;

throw new NotImplementedError(`${ref.type} ${ref.self.type}`);
}
/**
* If we're going in the initial direction (from the perspective of the initial = VERTEX)
* [ |--][--|--] <-- terminal
*/
[RayType.INITIAL]: (ref) => ref.self.switch({
// TODO REVERSE OF TERMINAL..

[RayType.TERMINAL]: (ref) => direction(ref).switch({ // TODO: This is applying the function again, should be separate?
// Found a next Vertex.
[RayType.VERTEX]: (self) => self,
}),
}),

// TODO: Possibly follow infintely
[RayType.REFERENCE]: () => { throw new NotImplementedError(); }
/**
* If we're going in the terminal direction (from the perspective of the initial = VERTEX)
* [--|--][--| ] <-- terminal
*/
[RayType.TERMINAL]: (ref) => ref.self.switch({

/**
* Many possible continuations (Vertical line is `ref.self`: Asking: 'What are the continuations at the terminal?`)
*
* ?
* [--|--][--| ]<-- ref superposed with ref.self
* ?
*/
[RayType.VERTEX]: () => {
throw new NotImplementedError()
},

// No continuations, either a self-reference, or different ways of halting.
[RayType.TERMINAL]: () => { throw new NotImplementedError() },

// A possible continuation
[RayType.INITIAL]: (ref) =>
direction(ref).switch({ // TODO: This is applying the function again, should be separate?
// Found a next Vertex.
[RayType.VERTEX]: (self) => self,
// [RayType.VERTEX]: (self) => { throw new NotImplementedError(); },

// TODO: Same, but defined a step further
// [RayType.TERMINAL]: () => Ray.None(),
[RayType.TERMINAL]: () => { throw new NotImplementedError(); },

// TODO: This switch could repeat infinitely, we need a way to hook into each step..
[RayType.INITIAL]: () => { throw new NotImplementedError(); },

// TODO: Similar to Initial, probably follow the reference, possibly infintely...
[RayType.REFERENCE]: (ref) => {
// throw new NotImplementedError(`${ref.type}/${ref.self.type} - ${ref.any.js}/${ref.self.any.js}`);
//
// if (ref.self.type === RayType.VERTEX)
// return ref.self;

throw new NotImplementedError(`${ref.type} ${ref.self.type}`);
}
}),

// TODO: Possibly follow infintely
[RayType.REFERENCE]: () => { throw new NotImplementedError(); }
}),

})
})
Expand All @@ -470,7 +500,7 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
return (ref: Ray) => method(ref)(direction(ref)); // TODO: Merge __next into __func, make this cleaner...
}

get next() { return Ray.___next(ref => ref.self.terminal)(this) }
get next() { return Ray.___next(ref => ref.self.terminal.as_reference())(this); }
// TODO: Could need equivalence/skip logic, "already was here", or say, necessarily, it should get visited again, ... again this thing is hard to say generally.
// TODO: This is the same with rewrite/compile/compose/dpo ...

Expand Down

0 comments on commit 15ac009

Please sign in to comment.