From 5b6805eede14c6ba6636f271c79d68b1e7da7c88 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Tue, 6 Mar 2012 08:41:42 +0000 Subject: [PATCH] refactored flatMap()'s default argument values into flatMap(fn) and flatMapTo(coll, fn) for easier completion/documentation --- stdlib/ktSrc/JavaIterables.kt | 10 +++++++++- stdlib/ktSrc/generated/ArraysFromJavaIterables.kt | 10 +++++++++- stdlib/ktSrc/generated/StandardFromJavaIterables.kt | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/stdlib/ktSrc/JavaIterables.kt b/stdlib/ktSrc/JavaIterables.kt index ddebe0115f0..14092aad1a2 100644 --- a/stdlib/ktSrc/JavaIterables.kt +++ b/stdlib/ktSrc/JavaIterables.kt @@ -83,7 +83,15 @@ inline fun > java.lang.Iterable.filterNotTo(result: C, * Returns the result of transforming each item in the collection to a one or more values which * are concatenated together into a single collection */ -inline fun java.lang.Iterable.flatMap(result: Collection = ArrayList(), transform: (T)-> Collection) : Collection { +inline fun java.lang.Iterable.flatMap(transform: (T)-> Collection) : Collection { + return flatMapTo(ArrayList(), transform) +} + +/** + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + */ +inline fun java.lang.Iterable.flatMapTo(result: Collection, transform: (T)-> Collection) : Collection { for (elem in this) { val coll = transform(elem) if (coll != null) { diff --git a/stdlib/ktSrc/generated/ArraysFromJavaIterables.kt b/stdlib/ktSrc/generated/ArraysFromJavaIterables.kt index ccbda01553b..8d5a80aa89d 100644 --- a/stdlib/ktSrc/generated/ArraysFromJavaIterables.kt +++ b/stdlib/ktSrc/generated/ArraysFromJavaIterables.kt @@ -86,7 +86,15 @@ inline fun > Array.filterNotTo(result: C, predicate: ( * Returns the result of transforming each item in the collection to a one or more values which * are concatenated together into a single collection */ -inline fun Array.flatMap(result: Collection = ArrayList(), transform: (T)-> Collection) : Collection { +inline fun Array.flatMap(transform: (T)-> Collection) : Collection { + return flatMapTo(ArrayList(), transform) +} + +/** + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + */ +inline fun Array.flatMapTo(result: Collection, transform: (T)-> Collection) : Collection { for (elem in this) { val coll = transform(elem) if (coll != null) { diff --git a/stdlib/ktSrc/generated/StandardFromJavaIterables.kt b/stdlib/ktSrc/generated/StandardFromJavaIterables.kt index ccd1d9dd4af..6f3470b2f73 100644 --- a/stdlib/ktSrc/generated/StandardFromJavaIterables.kt +++ b/stdlib/ktSrc/generated/StandardFromJavaIterables.kt @@ -74,7 +74,15 @@ inline fun > Iterable.filterNotTo(result: C, predicate * Returns the result of transforming each item in the collection to a one or more values which * are concatenated together into a single collection */ -inline fun Iterable.flatMap(result: Collection = ArrayList(), transform: (T)-> Collection) : Collection { +inline fun Iterable.flatMap(transform: (T)-> Collection) : Collection { + return flatMapTo(ArrayList(), transform) +} + +/** + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + */ +inline fun Iterable.flatMapTo(result: Collection, transform: (T)-> Collection) : Collection { for (elem in this) { val coll = transform(elem) if (coll != null) {