T
- The input type to the current stage of transformation. Some transforms produce a
different output type.public interface Transformable<T>
Modifier and Type | Method and Description |
---|---|
Transformable<T> |
concat(Iterable<? extends T> list)
Add items to the end of this Transformable (precat() adds to the beginning)
|
Transformable<T> |
drop(long numItems)
Ignore the first n items and return only those that come after.
|
Transformable<T> |
filter(Function1<? super T,Boolean> predicate)
Return only the items for which the given predicate returns true.
|
<U> Transformable<U> |
flatMap(Function1<? super T,Iterable<U>> f)
Transform each item into zero or more new items using the given function.
|
<U> U |
foldLeft(U u,
Function2<U,? super T,U> fun)
Apply the function to each item, accumulating the result in u.
|
<U> U |
foldLeft(U u,
Function2<U,? super T,U> fun,
Function1<? super U,Boolean> terminateWhen)
Normally you want to terminate by doing a take(), drop(), or takeWhile() before you get to the
fold, but if you need to terminate based on the complete result so far, you can provide your
own termination condition to this version of foldLeft().
|
<U> Transformable<U> |
map(Function1<? super T,? extends U> func)
Transform each item into exactly one new item using the given function.
|
Transformable<T> |
precat(Iterable<? extends T> list)
Add items to the beginning of this Transformable ("precat" is a PREpending version of conCAT).
|
Transformable<T> |
take(long numItems)
Return only the first n items.
|
Transformable<T> |
takeWhile(Function1<? super T,Boolean> predicate)
Return items from the beginning until the given predicate returns false.
|
default ImList<T> |
toImList()
Realize a thread-safe immutable list to access items quickly O(log32 n) by index.
|
default <K,V> ImMap<K,V> |
toImMap(Function1<? super T,Map.Entry<K,V>> f1)
Realize an unordered immutable hash map to very quickly O(1) look up values by key, but don't
care about ordering.
|
default ImSet<T> |
toImSet()
Realize an unordered immutable hash set to remove duplicates or very quickly O(1) tell whether
the set contains various items, but don't care about ordering.
|
default <K,V> ImSortedMap<K,V> |
toImSortedMap(Comparator<? super K> comp,
Function1<? super T,Map.Entry<K,V>> f1)
Realize an immutable, ordered (tree) map to quickly O(log2 n) look up values by key, but still
retrieve entries in key order.
|
default ImSortedSet<T> |
toImSortedSet(Comparator<? super T> comparator)
Realize an immutable, sorted (tree) set to quickly O(log2 n) test it contains items, but still
retrieve entries in order.
|
default List<T> |
toMutableList()
Realize a mutable list.
|
default <K,V> Map<K,V> |
toMutableMap(Function1<? super T,Map.Entry<K,V>> f1)
Realize a mutable hash map.
|
default Set<T> |
toMutableSet()
Realize a mutable hash set.
|
default <K,V> SortedMap<K,V> |
toMutableSortedMap(Comparator<? super K> comp,
Function1<? super T,Map.Entry<K,V>> f1)
Realize a mutable tree map.
|
default SortedSet<T> |
toMutableSortedSet(Comparator<? super T> comparator)
Returns a mutable tree set.
|
Transformable<T> concat(Iterable<? extends T> list)
list
- the items to addTransformable<T> drop(long numItems)
numItems
- the number of items at the beginning of this Transformable to ignoreTransformable<T> filter(Function1<? super T,Boolean> predicate)
predicate
- a function that returns true for items to keep, false for items to drop<U> Transformable<U> flatMap(Function1<? super T,Iterable<U>> f)
f
- yields a Transformable of 0 or more results for each input item.<U> U foldLeft(U u, Function2<U,? super T,U> fun)
u
- the accumulator and starting value. This will be passed to the function on the
first iteration to be combined with the first member of the underlying data source. For some
operations you'll need to pass an identity, e.g. for a sum, pass 0, for a product, pass 1 as
this parameter.fun
- combines each value in the list with the result so far. The initial result is u.<U> U foldLeft(U u, Function2<U,? super T,U> fun, Function1<? super U,Boolean> terminateWhen)
u
- the accumulator and starting value. This will be passed to the function on the
first iteration to be combined with the first member of the underlying data source. For some
operations you'll need to pass an identity, e.g. for a sum, pass 0, for a product, pass 1 as
this parameter.fun
- combines each value in the list with the result so far. The initial result is u.terminateWhen
- returns true when the termination condition is reached and will stop
processing the input at that time, returning the latest u.<U> Transformable<U> map(Function1<? super T,? extends U> func)
func
- a function that returns a new value for any value in the inputTransformable<T> precat(Iterable<? extends T> list)
list
- the items to addTransformable<T> take(long numItems)
numItems
- the maximum number of items in the returned view.Transformable<T> takeWhile(Function1<? super T,Boolean> predicate)
predicate
- the predicate (test function)default ImList<T> toImList()
default <K,V> ImMap<K,V> toImMap(Function1<? super T,Map.Entry<K,V>> f1)
f1
- Maps each item in this collection to a key/value pair. If the collection is composed
of Map.Entries (or Tuple2's), you can pass Function1.identity() here. This function must never
return null (filter out nulls in an earlier step of the transform if necessary).default ImSet<T> toImSet()
default <K,V> ImSortedMap<K,V> toImSortedMap(Comparator<? super K> comp, Function1<? super T,Map.Entry<K,V>> f1)
comp
- A comparator (on the keys) that defines the sort order inside the new map. This
becomes a permanent part of the map and all sub-maps or appended maps derived from it. If you
want to use a null key, make sure the comparator treats nulls correctly in all circumstances!f1
- Maps each item in this collection to a key/value pair. If the collection is composed
of Map.Entries, you can pass Function1.identity() here. In the case of a duplicate key, later
values in transform overwrite the earlier ones. The resulting map can contain zero or one
null key (if your comparator knows how to sort nulls) and any number of null values. This
function must never return null (filter out nulls in an earlier step of the transform if
necessary).default ImSortedSet<T> toImSortedSet(Comparator<? super T> comparator)
comparator
- Determines the ordering. If T implements Comparable, you can pass
Function2.defaultComparator() here.default List<T> toMutableList()
default <K,V> Map<K,V> toMutableMap(Function1<? super T,Map.Entry<K,V>> f1)
f1
- Maps keys to values. This function must never return null (filter out nulls in an
earlier step of the transform if necessary).default <K,V> SortedMap<K,V> toMutableSortedMap(Comparator<? super K> comp, Function1<? super T,Map.Entry<K,V>> f1)
comp
- A comparator (on the keys) that defines the sort order inside the new map. Null
keys are probably not allowed.f1
- Maps keys to values. This should never return null.default Set<T> toMutableSet()
default SortedSet<T> toMutableSortedSet(Comparator<? super T> comparator)
comparator
- Determines the ordering. If T implements Comparable, you can pass
Function2.defaultComparator() here.Copyright © 2016. All rights reserved.