From 6b51c2085876f6e23c129f218af71903688ede94 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 29 Feb 2012 14:30:39 +0000 Subject: [PATCH] avoid custom copy/paste on map methods for arrays --- stdlib/ktSrc/Arrays.kt | 13 ------------- stdlib/ktSrc/JavaCollections.kt | 12 ++++++++++++ stdlib/ktSrc/JavaUtil.kt | 12 ------------ stdlib/ktSrc/generated/ArraysFromJavaCollections.kt | 12 ++++++++++++ .../JavaUtilIterablesFromJavaCollections.kt | 12 ++++++++++++ .../ktSrc/generated/StandardFromJavaCollections.kt | 12 ++++++++++++ 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/stdlib/ktSrc/Arrays.kt b/stdlib/ktSrc/Arrays.kt index 8c842b6ef3f..cf8889b2821 100644 --- a/stdlib/ktSrc/Arrays.kt +++ b/stdlib/ktSrc/Arrays.kt @@ -106,16 +106,3 @@ inline fun Array.notEmpty() : Boolean = this.size > 0 /** Returns true if the array is empty */ inline fun Array.isEmpty() : Boolean = this.size == 0 - - -/** Returns a new List containing the results of applying the given function to each element in this collection */ -inline fun Array.map(transform : (T) -> R) : java.util.List { - return mapTo(java.util.ArrayList(this.size), transform) -} - -/** Transforms each element of this collection with the given function then adds the results to the given collection */ -inline fun > Array.mapTo(result: C, transform : (T) -> R) : C { - for (item in this) - result.add(transform(item)) - return result -} diff --git a/stdlib/ktSrc/JavaCollections.kt b/stdlib/ktSrc/JavaCollections.kt index c4802436512..673edbeec3f 100644 --- a/stdlib/ktSrc/JavaCollections.kt +++ b/stdlib/ktSrc/JavaCollections.kt @@ -1,3 +1,15 @@ package std.util import java.util.* + +/** Returns a new List containing the results of applying the given function to each element in this collection */ +inline fun java.util.Collection.map(transform : (T) -> R) : java.util.List { + return mapTo(java.util.ArrayList(this.size), transform) +} + +/** Transforms each element of this collection with the given function then adds the results to the given collection */ +inline fun > java.util.Collection.mapTo(result: C, transform : (T) -> R) : C { + for (item in this) + result.add(transform(item)) + return result +} diff --git a/stdlib/ktSrc/JavaUtil.kt b/stdlib/ktSrc/JavaUtil.kt index 3c54edceca7..50006784026 100644 --- a/stdlib/ktSrc/JavaUtil.kt +++ b/stdlib/ktSrc/JavaUtil.kt @@ -103,15 +103,3 @@ inline fun java.util.Collection.notEmpty() : Boolean = !this.isEmpty() inline fun java.util.Collection?.notNull() : Collection = if (this != null) this else Collections.EMPTY_LIST as Collection - -/** Returns a new List containing the results of applying the given function to each element in this collection */ -inline fun java.util.Collection.map(transform : (T) -> R) : java.util.List { - return mapTo(java.util.ArrayList(this.size), transform) -} - -/** Transforms each element of this collection with the given function then adds the results to the given collection */ -inline fun > java.util.Collection.mapTo(result: C, transform : (T) -> R) : C { - for (item in this) - result.add(transform(item)) - return result -} diff --git a/stdlib/ktSrc/generated/ArraysFromJavaCollections.kt b/stdlib/ktSrc/generated/ArraysFromJavaCollections.kt index 61eb0b907b2..3b1f0c23224 100644 --- a/stdlib/ktSrc/generated/ArraysFromJavaCollections.kt +++ b/stdlib/ktSrc/generated/ArraysFromJavaCollections.kt @@ -2,3 +2,15 @@ package std import java.util.* + +/** Returns a new List containing the results of applying the given function to each element in this collection */ +inline fun Array.map(transform : (T) -> R) : java.util.List { + return mapTo(java.util.ArrayList(this.size), transform) +} + +/** Transforms each element of this collection with the given function then adds the results to the given collection */ +inline fun > Array.mapTo(result: C, transform : (T) -> R) : C { + for (item in this) + result.add(transform(item)) + return result +} diff --git a/stdlib/ktSrc/generated/JavaUtilIterablesFromJavaCollections.kt b/stdlib/ktSrc/generated/JavaUtilIterablesFromJavaCollections.kt index 6faf9911981..0900ca1de80 100644 --- a/stdlib/ktSrc/generated/JavaUtilIterablesFromJavaCollections.kt +++ b/stdlib/ktSrc/generated/JavaUtilIterablesFromJavaCollections.kt @@ -2,3 +2,15 @@ package std.util import java.util.* + +/** Returns a new List containing the results of applying the given function to each element in this collection */ +inline fun java.lang.Iterable.map(transform : (T) -> R) : java.util.List { + return mapTo(java.util.ArrayList(), transform) +} + +/** Transforms each element of this collection with the given function then adds the results to the given collection */ +inline fun > java.lang.Iterable.mapTo(result: C, transform : (T) -> R) : C { + for (item in this) + result.add(transform(item)) + return result +} diff --git a/stdlib/ktSrc/generated/StandardFromJavaCollections.kt b/stdlib/ktSrc/generated/StandardFromJavaCollections.kt index 61eb0b907b2..e79bfb9f5e1 100644 --- a/stdlib/ktSrc/generated/StandardFromJavaCollections.kt +++ b/stdlib/ktSrc/generated/StandardFromJavaCollections.kt @@ -2,3 +2,15 @@ package std import java.util.* + +/** Returns a new List containing the results of applying the given function to each element in this collection */ +inline fun Iterable.map(transform : (T) -> R) : java.util.List { + return mapTo(java.util.ArrayList(), transform) +} + +/** Transforms each element of this collection with the given function then adds the results to the given collection */ +inline fun > Iterable.mapTo(result: C, transform : (T) -> R) : C { + for (item in this) + result.add(transform(item)) + return result +}