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 theSets
class. - Many of the collections have the same name as their mutable
java.util
counterparts, 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.util
counterpart by usingas...()
methods. e.g.Set.asSet()
. Such views are immutable. - Collections can be constructed from
java.util
collections 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
Set
that does not exist may return the same collection as no modifications were required.
See the project site for further examples and information.
-
Interface Summary Interface Description Builder<E,R> Builders
provide efficient implementations for incrementally building persistent collections.BuilderFactory<E,R> BuilderFactory
defines a factory interface for creatingBuilder
instances.Function<P,R> A generic function interface that takes a single parameter.IndexedList<E> IndexedList
implementations guarantee fast random access to elements viaList.get(int)
.Iterable<E> Iterable
defines collections that can be accessed via anIterator
.KeyFunction<K,V> KeyFunction
defines the interface for extracting a key from a value.LinkedList<E> LinkedList
implementations guarantee fast access to the head viaList.first()
and tail viaLinkedList.tail()
.List<E> List
defines an sequence of elements where the order is preserved.Map<K,V> Map
defines the interface for maps that associate keys with values.Set<E> Set defines the interface for a unique set of values as defined byObject.equals(Object)
.SortedMap<K,V> SortedMap defines the interface for maps that are sorted by their key.SortedSet<E> SortedSet
defines the interface for sets that are sorted.Traversable<E> Traversable
is the root of the collection hierarchy. -
Class Summary Class Description ArrayList<E> ArrayList
is anIndexedList
implementation backed by an array.ArrayLists ArrayLists
is the preferred method of constructing instances ofArrayList
.Cons<E> Cons constructs a new list by prepending a new element to an existing listConsList<E> ConsList
is a functionalLinkedList
implementation that constructs a list by prepending an element to another list.ConsListIterator<E> DerivedKeyHashMap<K,V> DerivedKeyHashMap
is aHashMap
variant where the key for theMap
is derived from the value stored.HashMap<K,V> HashMap
is an implementation ofMap
based on a hash trie.HashMap.Itr<K,V> HashSet<E> HashSet
is an implementation ofSet
backed by aHashMap
.IdentityKeyFunction<E> IdentityKeyFunction
is aKeyFunction
where the value can be used as a key.IndexedLists IndexedLists
is the preferred method of constructing instances ofIndexedList
.LinkedLists LinkedLists
is the preferred method of constructing instances ofLinkedList
.Maps Maps
is the preferred method of constructing instances ofMap
.Nil<E> Nil is the empty listPair<C1,C2> Pair
is a generic container for two components of specified types.Sets Sets
is the preferred method of constructing instances ofSet
.SortedMaps SortedMaps
is the preferred method of constructing instances ofSortedMap
.SortedSets SortedSets
is the preferred method of constructing instances ofSortedSet
.TreeMap<K,V> TreeSet<E> TreeSet
is an implementation ofSortedSet
backed by aTreeMap
.Vector<E> Vector is a general-purpose, immutable data structure.VectorBuilder<E> VectorIterator<E> VectorPointer<E>