KT-4139 FIXED

KT-4139 add "map" and "mapTo" methods in to "String" class.
This commit is contained in:
Mohammad Shamsi
2013-10-27 23:19:00 +08:00
parent ec42bfd1b2
commit d3eb23f233
2 changed files with 48 additions and 0 deletions
+16
View File
@@ -332,6 +332,22 @@ public inline fun String.partition(predicate: (Char) -> Boolean): Pair<String, S
return Pair(first.toString(), second.toString())
}
/**
* Returns a new List containing the results of applying the given *transform* function to each character in this string
*
*/
public inline fun <R> String.map(transform: (Char) -> R): List<R> = mapTo(ArrayList<R>(), transform)
/**
* Transforms each character of this string with the given *transform* function and
* adds each return value to the given *result* collection
*
*/
public inline fun <R, C: MutableCollection<in R>> String.mapTo(result: C, transform: (Char) -> R): C {
for (c in this) result.add(transform(c))
return result
}
/**
* Returns the result of transforming each character to one or more values which are concatenated together into a single list
*