A fine collection of collection-classes and utilities written in CoffeScript. Intended for Node- and client-side usage.
- Set - each entry is singular, no duplicates allowed
- Map - stores "entries" for provided "keys" like a dictionary
- Graph - a set of nodes where each node max be conected with other nodes making a path
- Set
- !Important! If an element has an .equals-method it is used to determine if other items are treated as the same - otherwise the is-operator (===) is used
add element
: Adds an element if it is not already containedaddAll ['a', 'b'] | otherSet
: adds all elements from an array or other setremove element
: Removes an elementremoveAll ['a', 'b'] | otherSet
: removes all elements from an array or other setclear()
: Removes all elementssize()
: Returns the number of elements contained in this setisEmtpy()
: Returns true if this set is emptyhas element
: Returns true ifelement.equals other
returns true for any other element or - if element does not have a method equals - if an contained element is equal in terms of (===)
fruit = new Set
fruit.add 'Apple'
fruit.add 'Banana'
fruit.add 'Cherry'
fruit.size() # => 3
fruit.add 'Apple' # adding the same entry twice
fruit.size() # => 3
fruit.has 'Cherry' # => true
fruit.has 'Raspberry' # => false
fruit.elements() # => ['Apple', 'Banana', 'Cherry']