sdk-common / com.tomtom.online.sdk.common.functional.collections / Iterables

Iterables

class Iterables

A collection of predefined general-purpose methods for working with Iterable.

Functions

allOf

static fun <A : Any!> allOf(iterable: MutableIterable<A>, predicate: Predicate<in A>): Boolean

Checks if all values of provided iterable satisfy given predicate

anyOf

static fun <A : Any!> anyOf(iterable: MutableIterable<A>, predicate: Predicate<in A>): Boolean

Checks if any values of provided iterable satisfy given predicate

filter

static fun <A : Any!> filter(iterable: MutableIterable<A>, predicate: Predicate<in A>): MutableIterable<A>

Returns an iterable consisting only of elements that satisfy the given predicate. As the method is working directly with iterables it needs to create one, thus it returns an ArrayList as an Iterable. If you want to get a different type please use Iterables#filter(Iterable, Supplier, Predicate) method instead.

static fun <A : Any!, C : MutableCollection<A>!> filter(iterable: MutableIterable<A>, supplier: Supplier<out C>, predicate: Predicate<in A>): C

Returns an iterable consisting only of elements that satisfy the given predicate. It is possible to specify the type of Iterable that should be returned.

flatMap

static fun <A : Any!, B : Any!> flatMap(iterable: MutableIterable<A>, mapper: (A) -> MutableIterable<B>!): MutableIterable<B>

Returns an iterable consisting of elements that were mapped with a function that is capable of returning an iterable. As the method is working directly with an iterable it needs to create one, thus it returns an ArrayList as an Iterable. If you want to get a different type please use Iterables#flatMap(Iterable, Supplier, Function1) method instead.

static fun <A : Any!, B : Any!, C : MutableCollection<B>!> flatMap(iterable: MutableIterable<A>, supplier: Supplier<out C>, mapper: (A) -> MutableIterable<B>!): C

Returns an iterable consisting of elements that were mapped with a function that is capable of returning an iterable.

fold

static fun <A : Any!, B : Any!> fold(iterable: MutableIterable<A>, initial: B, operator: (A, B) -> B): B

A higher-order function that takes a data structure, initial value and a combining operation to combine all the values into a single one.

forEach

static fun <A : Any!> forEach(iterable: MutableIterable<A>, consumer: Consumer1<A>): Unit

Performs the given action for each element of provided Iterable.

static fun <A : Any!> forEach(array: Array<A>, consumer: Consumer1<A>): Unit

Performs the given action for each element of provided array.

static fun <A : Any!> forEach(iterable: MutableIterable<A>, predicate: Predicate<A>, consumer: Consumer1<A>): Unit

Performs the given action for each element of the provided Iterable that satisfies the given Predicate.

getFirst

static fun <T : Any!> getFirst(iterable: MutableIterable<T>): Try<T>

Returns Try.Success with first element of provided iterable or failure if iterable is empty.

static fun <T : Any!> getFirst(iterable: MutableIterable<T>, predicate: Predicate<T>): Try<T>!

Tries to find first Iterable element that satisfies the given predicate.

getLast

static fun <T : Any!> getLast(iterable: MutableIterable<T>): Try<T>

Returns Try with last element of provided iterable or failure if iterable is empty.

static fun <T : Any!> getLast(iterable: MutableIterable<T>, predicate: Predicate<T>): Try<T>

Tries to find last Iterable element that satisfies the given predicate.

lazyMap

static fun <A : Any!, B : Any!> lazyMap(iterable: MutableIterable<A>, mapper: (A) -> B): MutableIterable<B>

Returns a view containing the result of applying mapper to each element of iterable.

map

static fun <A : Any!, B : Any!> map(iterable: MutableIterable<A>, mapper: (A) -> B): MutableIterable<B>

Returns an iterable consisting of the results of applying the specified mapper to the elements of the given iterable. As the method is working directly with an iterable it needs to create one, thus it returns an ArrayList as an Iterable. If you want to get a different type please use Iterables#map(Iterable, Supplier, Function1) method instead.

static fun <A : Any!, B : Any!, C : MutableCollection<B>!> map(iterable: MutableIterable<A>, supplier: Supplier<out C>, mapper: (A) -> B): C

Returns an iterable consisting of the results of applying the specified mapper to the elements of the given iterable. It's possible to specify what underlying Iterable implementation should be returned as a result.

reduce

static fun <A : Any!> reduce(iterable: MutableIterable<A>, operator: (A, A) -> A): A

A higher-order function that takes a data structure and a combining operation to combine all the values in the said structure into a single one.