montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 185 forks source link

Allow deque to have a max length #211

Open danbopes opened 5 years ago

danbopes commented 5 years ago

Following along with python's deque here, I think it would be incredibly useful if you provided a max length parameter, to prevent a collection going over a certain size.

From python's docs:

If maxlen is not specified or is None, deques may grow to an arbitrary length. Otherwise, the deque is bounded to the specified maximum length. Once a bounded length deque is full, when new items are added, a corresponding number of items are discarded from the opposite end. Bounded length deques provide functionality similar to the tail filter in Unix. They are also useful for tracking transactions and other pools of data where only the most recent activity is of interest.