Package com.github.andrewoma.dexx.collection
package com.github.andrewoma.dexx.collection
Dexx collections are a port of Scala's immutable, persistent collection classes to pure Java.
Persistent in the context of functional data structures means the data structure preserves the previous version of itself when modified. This means any reference to a collection is effectively immutable. However, modifications can be made by returning a new version of the data structure, leaving the original structure unchanged.
The following diagram shows the key interfaces (blue) and classes (green) in this package:
Usage Notes:
- Each of the collection types has an associated companion class (plural form) that is the
preferred method of construction. e.g. To create a
Set, use theSetsclass. - Many of the collections have the same name as their mutable
java.utilcounterparts, however they are not directly related. This is due to the interfaces being fundamentally incompatible as operations the "modify" collections must return a new instance for persistent collections. - Collections can be viewed as their
java.utilcounterpart by usingas...()methods. e.g.Set.asSet(). Such views are immutable. - Collections can be constructed from
java.utilcollections by using thecopyOf(...)methods in the companion classes. e.g.Sets.copyOf(java.lang.Iterable). - While operations on collections often return a new instance that reflects the modifications,
this is not a guarantee. e.g. Attempting to remove an element from a
Setthat does not exist may return the same collection as no modifications were required.
See the project site for further examples and information.
-
ClassDescriptionArrayList<E>
ArrayListis anIndexedListimplementation backed by an array.ArrayListsis the preferred method of constructing instances ofArrayList.Builder<E,R> Buildersprovide efficient implementations for incrementally building persistent collections.BuilderFactory<E,R> BuilderFactorydefines a factory interface for creatingBuilderinstances.Cons<E>Cons constructs a new list by prepending a new element to an existing listConsList<E>ConsListis a functionalLinkedListimplementation that constructs a list by prepending an element to another list.DerivedKeyHashMap<K,V> DerivedKeyHashMapis aHashMapvariant where the key for theMapis derived from the value stored.Function<P,R> A generic function interface that takes a single parameter.HashMap<K,V> HashMapis an implementation ofMapbased on a hash trie.HashMap.Itr<K,V> HashSet<E>HashSetis an implementation ofSetbacked by aHashMap.IdentityKeyFunctionis aKeyFunctionwhere the value can be used as a key.IndexedList<E>IndexedListimplementations guarantee fast random access to elements viaList.get(int).IndexedListsis the preferred method of constructing instances ofIndexedList.Iterable<E>Iterabledefines collections that can be accessed via anIterator.KeyFunction<K,V> KeyFunctiondefines the interface for extracting a key from a value.LinkedList<E>LinkedListimplementations guarantee fast access to the head viaList.first()and tail viaLinkedList.tail().LinkedListsis the preferred method of constructing instances ofLinkedList.List<E>Listdefines an sequence of elements where the order is preserved.Map<K,V> Mapdefines the interface for maps that associate keys with values.Mapsis the preferred method of constructing instances ofMap.Nil<E>Nil is the empty listPair<C1,C2> Pairis a generic container for two components of specified types.Set<E>Set defines the interface for a unique set of values as defined byObject.equals(Object).Setsis the preferred method of constructing instances ofSet.SortedMap<K,V> SortedMap defines the interface for maps that are sorted by their key.SortedMapsis the preferred method of constructing instances ofSortedMap.SortedSet<E>SortedSetdefines the interface for sets that are sorted.SortedSetsis the preferred method of constructing instances ofSortedSet.Traversable<E>Traversableis the root of the collection hierarchy.TreeMap<K,V> TreeSet<E>TreeSetis an implementation ofSortedSetbacked by aTreeMap.Vector<E>Vector is a general-purpose, immutable data structure.