Skip to content

Commit c50f627

Browse files
committed
add: implement peek and remove
1 parent a996b2d commit c50f627

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/immutable_sequence.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@
7878
return split[1].peekFirst();
7979
};
8080

81+
/**
82+
* Get the first element in the sequence.
83+
* @return {*}
84+
*/
85+
ImmutableSequence.prototype.peekFirst = function () {
86+
return this.tree_.peekFirst();
87+
};
88+
89+
/**
90+
* Get the last element in the sequence.
91+
* @return {*}
92+
*/
93+
ImmutableSequence.prototype.peekLast = function () {
94+
return this.tree_.peekLast();
95+
};
96+
8197
/**
8298
* Add an element to the front of the sequence.
8399
* @param {*} v
@@ -96,5 +112,21 @@
96112
return new ImmutableSequence(this.tree_.addLast(v));
97113
};
98114

115+
/**
116+
* Remove an element from the front of the sequence.
117+
* @return {ImmutableSequence}
118+
*/
119+
ImmutableSequence.prototype.removeFirst = function () {
120+
return new ImmutableSequence(this.tree_.removeFirst());
121+
};
122+
123+
/**
124+
* Remove an element from the end of the sequence.
125+
* @return {ImmutableSequence}
126+
*/
127+
ImmutableSequence.prototype.removeLast = function () {
128+
return new ImmutableSequence(this.tree_.removeLast());
129+
};
130+
99131
return ImmutableSequence;
100132
}));

0 commit comments

Comments
 (0)