scoop:scoop.std:0.1.0
src/collections/destinations.scoop
Selected production source · src/collections/destinations.scoop
1
package scoop.collections3
/**4
* Adds all source elements to the destination and returns it.5
*/6
public fun <T> Iterable<T>.toCollection(destination: MutableList<T>): MutableList<T> {7
for (element in toList<T>()) destination.add(element)8
return destination9
}11
/**12
* Adds all source elements to the destination and returns it.13
*/14
public fun <T> Iterable<T>.toCollection(destination: MutableSet<T>): MutableSet<T> {15
for (element in toList<T>()) destination.add(element)16
return destination17
}19
/**20
* Appends transformed elements to the destination and returns it.21
*/22
public fun <T, R> Iterable<T>.mapTo(destination: MutableList<R>, transform: (T) -> R): MutableList<R> {23
for (element in toList<T>()) destination.add(transform(element))24
return destination25
}27
/**28
* Appends transformed elements to the destination and returns it.29
*/30
public fun <T, R> Iterable<T>.mapTo(destination: MutableSet<R>, transform: (T) -> R): MutableSet<R> {31
for (element in toList<T>()) destination.add(transform(element))32
return destination33
}35
/**36
* Appends matching elements to the destination and returns it.37
*/38
public fun <T> Iterable<T>.filterTo(destination: MutableList<T>, predicate: (T) -> Boolean): MutableList<T> {39
for (element in toList<T>()) { if (predicate(element)) destination.add(element) }40
return destination41
}43
/**44
* Appends matching elements to the destination and returns it.45
*/46
public fun <T> Iterable<T>.filterTo(destination: MutableSet<T>, predicate: (T) -> Boolean): MutableSet<T> {47
for (element in toList<T>()) { if (predicate(element)) destination.add(element) }48
return destination49
}51
/**52
* Appends each transformed iterable to the destination and returns it.53
*/54
public fun <T, R> Iterable<T>.flatMapTo(destination: MutableList<R>, transform: (T) -> Iterable<R>): MutableList<R> {55
for (element in toList<T>()) {56
val values = transform(element).toList()57
for (value in values) destination.add(value)58
}59
return destination60
}62
/**63
* Appends each transformed iterable to the destination and returns it.64
*/65
public fun <T, R> Iterable<T>.flatMapTo(destination: MutableSet<R>, transform: (T) -> Iterable<R>): MutableSet<R> {66
for (element in toList<T>()) {67
val values = transform(element).toList()68
for (value in values) destination.add(value)69
}70
return destination71
}