Skip to content

Commit

Permalink
feat(dcons): add asHead()/asTail()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 21, 2018
1 parent 3947419 commit 19f7e76
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/dcons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,32 @@ export class DCons<T> implements
return this;
}

asHead(cell: ConsCell<T>) {
if (cell === this.head) {
return this;
}
this.remove(cell);
this.head.prev = cell;
cell.next = this.head;
cell.prev = undefined;
this.head = cell;
this._length++;
return this;
}

asTail(cell: ConsCell<T>) {
if (cell === this.tail) {
return this;
}
this.remove(cell);
this.tail.next = cell;
cell.prev = this.tail;
cell.next = undefined;
this.tail = cell;
this._length++;
return this;
}

toString() {
let res: any = [];
let cell = this.head;
Expand Down

0 comments on commit 19f7e76

Please sign in to comment.