public interface UnmodIterable<T> extends Iterable<T>, Transformable<T>
Modifier and Type | Interface and Description |
---|---|
static class |
UnmodIterable.AbstractUnmodIterable<T>
Implements equals and hashCode() methods compatible with all java.util collections (this
algorithm is not order-dependent) and toString which takes the name of the sub-class.
|
Modifier and Type | Method and Description |
---|---|
default UnmodIterable<T> |
concat(Iterable<? extends T> list)
Add items to the end of this Transformable (precat() adds to the beginning)
|
default UnmodIterable<T> |
drop(long n)
Ignore the first n items and return only those that come after.
|
default UnmodIterable<T> |
filter(Fn1<? super T,Boolean> f)
Return only the items for which the given predicate returns true.
|
default <B> UnmodIterable<B> |
flatMap(Fn1<? super T,Iterable<B>> f)
Transform each item into zero or more new items using the given function.
|
default <B> B |
fold(B ident,
Fn2<? super B,? super T,B> reducer)
Apply the function to each item, accumulating the result in u.
|
default <G,B> Or<G,B> |
foldUntil(G accum,
Fn2<? super G,? super T,B> terminator,
Fn2<? super G,? super T,G> reducer)
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 fold().
|
static int |
hash(Iterable is)
This is correct, but O(n).
|
default Option<T> |
head()
The first item in this sequence.
|
UnmodIterator<T> |
iterator()
A one-time use, mutable, not-thread-safe way to get each value of the underling collection in
turn.
|
default <B> UnmodIterable<B> |
map(Fn1<? super T,? extends B> f)
Transform each item into exactly one new item using the given function.
|
default UnmodIterable<T> |
precat(Iterable<? extends T> list)
Add items to the beginning of this Transformable ("precat" is a PREpending version of conCAT).
|
default UnmodIterable<T> |
take(long numItems)
Return only the first n items.
|
default UnmodIterable<T> |
takeWhile(Fn1<? super T,Boolean> f)
Return items from the beginning until the given predicate returns false.
|
static String |
toString(String name,
Iterable iterable)
Computes a reasonable to-string.
|
forEach, spliterator
toImList, toImMap, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableSet, toMutableSortedMap, toMutableSortedSet
static int hash(Iterable is)
UnmodIterator<T> iterator()
default UnmodIterable<T> concat(Iterable<? extends T> list)
concat
in interface Transformable<T>
list
- the items to adddefault UnmodIterable<T> precat(Iterable<? extends T> list)
precat
in interface Transformable<T>
list
- the items to adddefault UnmodIterable<T> drop(long n)
drop
in interface Transformable<T>
n
- the number of items at the beginning of this Transformable to ignoredefault <B> B fold(B ident, Fn2<? super B,? super T,B> reducer)
fold
in interface Transformable<T>
ident
- 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.reducer
- combines each value in the list with the result so far. The initial result is u.default <G,B> Or<G,B> foldUntil(G accum, Fn2<? super G,? super T,B> terminator, Fn2<? super G,? super T,G> reducer)
foldUntil
in interface Transformable<T>
accum
- 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.terminator
- return null to continue processing. Return non-null to terminate
the foldUntil and return Or.bad of this value. This function is called at the beginning
of each "loop", thus it's first called with the original value of accum and the first item
to process. Returning non-null immediately will prevent the reducer from ever being called.reducer
- combines each value in the list with the result so far. The initial result is u.Or
where the Or.good()
is an eagerly evaluated result and
Or.bad()
is whatever terminateWhen returned.default UnmodIterable<T> filter(Fn1<? super T,Boolean> f)
filter
in interface Transformable<T>
f
- a function that returns true for items to keep, false for items to dropdefault <B> UnmodIterable<B> flatMap(Fn1<? super T,Iterable<B>> f)
flatMap
in interface Transformable<T>
f
- yields a Transformable of 0 or more results for each input item.default <B> UnmodIterable<B> map(Fn1<? super T,? extends B> f)
map
in interface Transformable<T>
f
- a function that returns a new value for any value in the inputdefault UnmodIterable<T> take(long numItems)
take
in interface Transformable<T>
numItems
- the maximum number of items in the returned view.default UnmodIterable<T> takeWhile(Fn1<? super T,Boolean> f)
takeWhile
in interface Transformable<T>
f
- the predicate (test function)Copyright © 2017. All rights reserved.