Class IterableHelpers
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.IterableHelpers
-
@API(EXPERIMENTAL) public class IterableHelpers extends Object
Helper methods forIterable
s.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R>
Iterable<R>flatMap(Iterable<T> source, Function<? super T,? extends Iterable<R>> mapper)
Flat-maps given function to the given iterable and returns a new iterable.static <T,R>
Iterable<R>map(Iterable<T> source, Function<? super T,R> mapper)
Maps given function to the given iterable and returns a new iterable.static <T> Iterable<T>
orElse(Iterable<T> source, Iterable<T> otherIterable)
Returns an alternative iterable if the given source iterable is empty.static <T> Iterable<T>
orElseOf(Iterable<T> source, T value)
Returns an alternative singleton iterable if the given source iterable is empty.
-
-
-
Method Detail
-
flatMap
public static <T,R> Iterable<R> flatMap(@Nonnull Iterable<T> source, @Nonnull Function<? super T,? extends Iterable<R>> mapper)
Flat-maps given function to the given iterable and returns a new iterable. This is akin to compositions based onStream
, however, allows for restarting the iteration as per general contract inIterable
.- Type Parameters:
T
- type of source iterableR
- type the given mapper function returns iterables of- Parameters:
source
- source iterablemapper
- mapper function to map fromT
toIterable
ofR
- Returns:
- an iterable of type
R
that is the conceptual flat map ofsource
usingmapper
-
map
public static <T,R> Iterable<R> map(@Nonnull Iterable<T> source, @Nonnull Function<? super T,R> mapper)
Maps given function to the given iterable and returns a new iterable. This is akin to compositions based onStream
, however, allows for restarting the iteration as per general contract inIterable
.- Type Parameters:
T
- type of source iterableR
- type the given mapper function returns- Parameters:
source
- source iterablemapper
- mapper function to map fromT
toIterable
ofR
- Returns:
- an iterable of type
R
that is the conceptual map ofsource
usingmapper
-
orElseOf
public static <T> Iterable<T> orElseOf(@Nonnull Iterable<T> source, @Nonnull T value)
Returns an alternative singleton iterable if the given source iterable is empty.- Type Parameters:
T
- type parameter of the given iterable- Parameters:
source
- sourcevalue
- value to use if source is empty- Returns:
- an iterable of type
T
that returns the original iterable if it is not empty, or a singleton iterable composed of justvalue
.
-
orElse
public static <T> Iterable<T> orElse(@Nonnull Iterable<T> source, @Nonnull Iterable<T> otherIterable)
Returns an alternative iterable if the given source iterable is empty.- Type Parameters:
T
- type parameter of the given iterable- Parameters:
source
- sourceotherIterable
- iterable to return if source is empty- Returns:
- an iterable of type
T
that returns the original iterable if it is not empty, orotherIterable
-
-