+ +
+

ifNotEmpty

+
+
inline fun <T : Collection<*>, SuperTypeOfT, SuperTypeOfT : Iterable<*>> T.ifNotEmpty(transformation: (T) -> SuperTypeOfT): SuperTypeOfT(source)

Checks if this collection is empty and if not applies the given transformation.

Return

this if the given collection is empty, otherwise the result of applying this collection to the given transformation.

Since

1.2.0

Parameters

transformation

the function which transforms this collection into SuperTypeOfT (at least an Iterable)

T

The type of the receiver -- a Collection or one of its subtypes

SuperTypeOfT

The result type can also be a super type of T as long as it doesn't go beyond Iterable. In theory, we would not need to establish this constraint but in all cases we came across so far we never wanted to end up with Any. E.g. if T = List then we don't want that the transformation returns an Array as otherwise we have a List in case it is empty and an Array otherwise and the least upper bound of those two types is Any, i.e. we would end up with SuperTypeOfT = Any.

+