In JavaScript, it is trivial to create a pair of nodes that reference each other in an infinite loop:
var node = item =>
next =>
previous => {
return {
item: item,
previous: previous,
next: next
};
};
var z = {
a: node('a')(() => z.b)(() => z.b),
b: node('b')(() => z.a)(() => z.a)
};
Grab either z.a or z.b and you will be able to call next() and previous() infinitely.
Is it possible to instantiate, for instance, for a carousel with any size that can be scrolled in either direction, a circular linked list that can be of an arbitrary number of elements when it is instantiated?
I've read some things from the Haskell Wiki on "Tying the Knot", and found examples in Scala, but I'm not sure how to make these work in JavaScript.
() => z.abeforezgot defined.