T
- Component typepublic interface Iterable<T> extends Iterable<T>
java.lang.Iterable
and basis of all Value
types, e.g. controls, collections et al.Modifier and Type | Method and Description |
---|---|
default <U> boolean |
corresponds(Iterable<U> that,
java.util.function.BiPredicate<T,U> predicate)
Tests whether every element of this iterable relates to the corresponding element of another iterable by
satisfying a test predicate.
|
default boolean |
eq(Object o)
A smoothing replacement for
equals . |
default boolean |
exists(java.util.function.Predicate<? super T> predicate)
Checks, if an element exists such that the predicate holds.
|
default boolean |
forAll(java.util.function.Predicate<? super T> predicate)
Checks, if the given predicate holds for all elements.
|
default void |
forEach(java.util.function.Consumer<? super T> action)
Performs an action on each element.
|
default Iterator<IndexedSeq<T>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
Iterator<T> |
iterator()
Returns a rich
javaslang.collection.Iterator . |
default Iterator<IndexedSeq<T>> |
sliding(int size)
|
default Iterator<IndexedSeq<T>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Iterable . |
spliterator
default <U> boolean corresponds(Iterable<U> that, java.util.function.BiPredicate<T,U> predicate)
U
- Component type of that iterablethat
- the other iterablepredicate
- the test predicate, which relates elements from both iterablestrue
if both iterables have the same length and predicate(x, y)
is true
for all corresponding elements x
of this iterable and y
of that
,
otherwise false
.default boolean eq(Object o)
equals
. It is similar to Scala's ==
but better in the way
that it is not limited to collection types, e.g. `Some(1) eq List(1)`, `None eq Failure(x)` etc.
In a nutshell: eq checks congruence of structures and equality of contained values.
Example:
// ((1, 2), ((3))) => structure: (()(())) values: 1, 2, 3
final Iterable<?> i1 = List.of(List.of(1, 2), Arrays.asList(List.of(3)));
final Iterable<?> i2 = Queue.of(Stream.of(1, 2), List.of(Lazy.of(() -> 3)));
assertThat(i1.eq(i2)).isTrue();
Semantics:
o == this : true
o instanceof javaslang.Iterable : iterable elements are eq, non-iterable elements equals, for all (o1, o2) in (this, o)
o instanceof java.lang.Iterable : this eq Iterator.ofAll((java.lang.Iterable<?>) o);
otherwise : false
o
- An objectdefault boolean exists(java.util.function.Predicate<? super T> predicate)
predicate
- A PredicateNullPointerException
- if predicate
is nulldefault boolean forAll(java.util.function.Predicate<? super T> predicate)
predicate
- A PredicateNullPointerException
- if predicate
is nulldefault void forEach(java.util.function.Consumer<? super T> action)
forEach
in interface Iterable<T>
action
- A Consumer
NullPointerException
- if action
is nulldefault Iterator<IndexedSeq<T>> grouped(int size)
Traversable
into fixed size blocks.
Let length be the length of this Iterable. Then grouped is defined as follows:
this.isEmpty()
, the resulting Iterator
is empty.size <= length
, the resulting Iterator
will contain length / size
blocks of size
size
and maybe a non-empty block of size length % size
, if there are remaining elements.size > length
, the resulting Iterator
will contain one block of size length
.
[].grouped(1) = []
[].grouped(0) throws
[].grouped(-1) throws
[1,2,3,4].grouped(2) = [[1,2],[3,4]]
[1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]]
[1,2,3,4].grouped(5) = [[1,2,3,4]]
Please note that grouped(int)
is a special case of sliding(int, int), i.e.
grouped(size)
is the same as sliding(size, size)
.size
- a positive block sizeIllegalArgumentException
- if size
is negative or zerodefault Iterator<IndexedSeq<T>> sliding(int size)
size
- a positive window sizeIllegalArgumentException
- if size
is negative or zerodefault Iterator<IndexedSeq<T>> sliding(int size, int step)
size
and step
size over this Iterable
.
Examples:
[].sliding(1,1) = []
[1,2,3,4,5].sliding(2,3) = [[1,2],[4,5]]
[1,2,3,4,5].sliding(2,4) = [[1,2],[5]]
[1,2,3,4,5].sliding(2,5) = [[1,2]]
[1,2,3,4].sliding(5,3) = [[1,2,3,4],[4]]
size
- a positive window sizestep
- a positive step sizeIllegalArgumentException
- if size
or step
are negative or zeroCopyright © 2015. All Rights Reserved.