Scoop API

scoop:scoop.std:0.1.0

src/collections/destinations.scoop

Selected production source · src/collections/destinations.scoop

1package scoop.collections
3/**
4 * Adds all source elements to the destination and returns it.
5 */
6public fun <T> Iterable<T>.toCollection(destination: MutableList<T>): MutableList<T> {
7 for (element in toList<T>()) destination.add(element)
8 return destination
9}
11/**
12 * Adds all source elements to the destination and returns it.
13 */
14public fun <T> Iterable<T>.toCollection(destination: MutableSet<T>): MutableSet<T> {
15 for (element in toList<T>()) destination.add(element)
16 return destination
19/**
20 * Appends transformed elements to the destination and returns it.
21 */
22public 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 destination
27/**
28 * Appends transformed elements to the destination and returns it.
29 */
30public 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 destination
35/**
36 * Appends matching elements to the destination and returns it.
37 */
38public 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 destination
43/**
44 * Appends matching elements to the destination and returns it.
45 */
46public 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 destination
51/**
52 * Appends each transformed iterable to the destination and returns it.
53 */
54public 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 destination
62/**
63 * Appends each transformed iterable to the destination and returns it.
64 */
65public 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 destination