Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2013 16:20
Show Gist options
  • Save anonymous/5868876 to your computer and use it in GitHub Desktop.
Save anonymous/5868876 to your computer and use it in GitHub Desktop.
function LazySeq(head, tail) {
this.head = head;
this.tail = tail;
}
LazySeq.prototype.first = function() {
return this.head;
}
LazySeq.prototype.rest = function() {
return this.tail();
}
function Cons(head, tail) {
this.head = head;
this.tail = tail;
}
Cons.prototype.first = function() {
return this.head;
}
Cons.prototype.rest = function() {
return this.tail;
}
function first(seq) {
return seq.first();
}
function rest(seq) {
return seq.rest();
}
console.log(first(new LazySeq(1, null)));
console.log(first(new Cons(1, null)));
console.log(first(rest(new Cons(1,new LazySeq(2, function() { return new LazySeq(3, null)})))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment