Migrate kotlin sources, maven projects and stdlib to new lambda syntax

This commit is contained in:
Stanislav Erokhin
2015-04-01 16:36:44 +03:00
parent e0988de707
commit b703f59e04
74 changed files with 136 additions and 140 deletions
+22 -22
View File
@@ -843,140 +843,140 @@ public fun <T> Stream<T>.plus(stream: Stream<T>): Stream<T> {
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Array<out T>.zip(array: Array<out R>): List<Pair<T, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> BooleanArray.zip(array: Array<out R>): List<Pair<Boolean, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> ByteArray.zip(array: Array<out R>): List<Pair<Byte, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> CharArray.zip(array: Array<out R>): List<Pair<Char, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> DoubleArray.zip(array: Array<out R>): List<Pair<Double, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> FloatArray.zip(array: Array<out R>): List<Pair<Float, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> IntArray.zip(array: Array<out R>): List<Pair<Int, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> LongArray.zip(array: Array<out R>): List<Pair<Long, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> ShortArray.zip(array: Array<out R>): List<Pair<Short, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Iterable<T>.zip(array: Array<out R>): List<Pair<T, R>> {
return merge(array) { (t1, t2) -> t1 to t2 }
return merge(array) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Array<out T>.zip(other: Iterable<R>): List<Pair<T, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> BooleanArray.zip(other: Iterable<R>): List<Pair<Boolean, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> ByteArray.zip(other: Iterable<R>): List<Pair<Byte, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> CharArray.zip(other: Iterable<R>): List<Pair<Char, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> DoubleArray.zip(other: Iterable<R>): List<Pair<Double, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> FloatArray.zip(other: Iterable<R>): List<Pair<Float, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> IntArray.zip(other: Iterable<R>): List<Pair<Int, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> LongArray.zip(other: Iterable<R>): List<Pair<Long, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <R> ShortArray.zip(other: Iterable<R>): List<Pair<Short, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Iterable<T>.zip(other: Iterable<R>): List<Pair<T, R>> {
return merge(other) { (t1, t2) -> t1 to t2 }
return merge(other) { t1, t2 -> t1 to t2 }
}
/**
@@ -997,7 +997,7 @@ public fun String.zip(other: String): List<Pair<Char, Char>> {
* Resulting sequence has length of shortest input sequences.
*/
public fun <T, R> Sequence<T>.zip(sequence: Sequence<R>): Sequence<Pair<T, R>> {
return MergingSequence(this, sequence) { (t1, t2) -> t1 to t2 }
return MergingSequence(this, sequence) { t1, t2 -> t1 to t2 }
}
@@ -1007,6 +1007,6 @@ deprecated("Migrate to using Sequence<T> and respective functions")
* Resulting stream has length of shortest input streams.
*/
public fun <T, R> Stream<T>.zip(stream: Stream<R>): Stream<Pair<T, R>> {
return MergingStream(this, stream) { (t1, t2) -> t1 to t2 }
return MergingStream(this, stream) { t1, t2 -> t1 to t2 }
}
@@ -390,7 +390,7 @@ public fun <T> Iterator<T>.reverse() : List<T> {
deprecated("Replace Iterator<T> with Sequence<T> by using sequence() function instead of iterator()")
public inline fun <T, R: Comparable<R>> Iterator<T>.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) f: (T) -> R) : List<T> {
val sortedList = toCollection(ArrayList<T>())
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
val sortBy: Comparator<T> = comparator<T> {x: T, y: T ->
val xr = f(x)
val yr = f(y)
xr.compareTo(yr)
@@ -76,7 +76,7 @@ public object Delegates {
* @param onChange the callback which is called when the property value is changed.
*/
public fun observable<T>(initial: T, onChange: (desc: PropertyMetadata, oldValue: T, newValue: T) -> Unit): ReadWriteProperty<Any?, T> {
return ObservableProperty<T>(initial) { (desc, old, new) ->
return ObservableProperty<T>(initial) { desc, old, new ->
onChange(desc, old, new)
true
}
@@ -257,7 +257,7 @@ public abstract class MapVar<T, K, V>() : MapVal<T, K, V>(), ReadWriteProperty<T
}
private val defaultKeyProvider:(PropertyMetadata) -> String = {it.name}
private val defaultValueProvider:(Any?, Any?) -> Nothing = {(thisRef, key) -> throw KeyMissingException("$key is missing from $thisRef")}
private val defaultValueProvider:(Any?, Any?) -> Nothing = {thisRef, key -> throw KeyMissingException("$key is missing from $thisRef")}
/**
* Implements a read-only property delegate that stores the property values in a given map instance and uses the given
+1 -1
View File
@@ -35,7 +35,7 @@ class OrderingTest {
}
Test fun sortComparatorThenComparator() {
val comparator = comparator<Item> {(a, b) -> a.name.compareTo(b.name) } thenComparator {(a, b) -> a.rating.compareTo(b.rating) }
val comparator = comparator<Item> { a, b -> a.name.compareTo(b.name) } thenComparator { a, b -> a.rating.compareTo(b.rating) }
val diff = comparator.compare(v1, v2)
assertTrue(diff > 0)
@@ -200,7 +200,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
Test
fun mapIndexed() {
val shortened = data.mapIndexed {(index, value) -> value.substring(0..index) }
val shortened = data.mapIndexed { index, value -> value.substring(0..index) }
assertEquals(2, shortened.size())
assertEquals(listOf("f", "ba"), shortened)
}
@@ -84,7 +84,7 @@ public class SequenceTest {
}
test fun foldReducesTheFirstNElements() {
val sum = {(a: Int, b: Int) -> a + b }
val sum = { a: Int, b: Int -> a + b }
assertEquals(listOf(13, 21, 34, 55, 89).fold(0, sum), fibonacci().filter { it > 10 }.take(5).fold(0, sum))
}
@@ -93,7 +93,7 @@ public class SequenceTest {
}
test fun mapAndTakeWhileExtractTheTransformedElements() {
assertEquals(listOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile {(i: Int) -> i < 20 }.toList())
assertEquals(listOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
@@ -36,7 +36,7 @@ class SerializableTest() : TestCase() {
fun testComplexClosure() {
val y = 12
val fn1 = {(x: Int) -> (x + y).toString() }
val fn1 = { x: Int -> (x + y).toString() }
val fn2: Int.(Int) -> String = { fn1(this + it) }
val byteOutputStream = ByteArrayOutputStream()
@@ -8,7 +8,7 @@ class IteratorsJVMTest {
test fun flatMapAndTakeExtractTheTransformedElements() {
fun intToBinaryDigits() = { (i: Int) ->
fun intToBinaryDigits() = { i: Int ->
val binary = Integer.toBinaryString(i)!!
var index = 0
sequence<Char> { if (index < binary.length()) binary.get(index++) else null }
@@ -18,7 +18,7 @@ class IteratorsTest {
}
test fun foldReducesTheFirstNElements() {
val sum = { (a: Int, b: Int) -> a + b }
val sum = { a: Int, b: Int -> a + b }
assertEquals(arrayListOf(13, 21, 34, 55, 89).fold(0, sum), fibonacci().filter { it > 10 }.take(5).fold(0, sum))
}
@@ -27,11 +27,11 @@ class IteratorsTest {
}
test fun mapAndTakeWhileExtractTheTransformedElements() {
assertEquals(arrayListOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { (i: Int) -> i < 20 }.toList())
assertEquals(arrayListOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun mapIndexed() {
assertEquals(arrayListOf(0, 1, 2, 6, 12), fibonacci().mapIndexed { index, value -> index * value }.takeWhile {(i: Int) -> i < 20 }.toList())
assertEquals(arrayListOf(0, 1, 2, 6, 12), fibonacci().mapIndexed { index, value -> index * value }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
@@ -12,7 +12,7 @@ class JavautilCollectionsTest {
val TEST_LIST = array(2, 0, 9, 7, 1).toList()
val SORTED_TEST_LIST = array(0, 1, 2, 7, 9).toList()
val MAX_ELEMENT = 9
val COMPARATOR = comparator { (x: Int, y: Int) -> if (x > y) 1 else if (x < y) -1 else 0 }
val COMPARATOR = comparator { x: Int, y: Int -> if (x > y) 1 else if (x < y) -1 else 0 }
test fun maxWithComparator() {
assertEquals(MAX_ELEMENT, Collections.max(TEST_LIST, COMPARATOR))
@@ -72,7 +72,7 @@ class TestObservablePropertyInChangeSupport: WithBox, ChangeSupport() {
class TestObservableProperty: WithBox {
var result = false
var b by Delegates.observable(1, {(pd, o, n) -> result = true})
var b by Delegates.observable(1, { pd, o, n -> result = true})
override fun box(): String {
b = 4
@@ -86,7 +86,7 @@ class A(val p: Boolean)
class TestVetoableProperty: WithBox {
var result = false
var b by Delegates.vetoable(A(true), {(pd, o, n) -> result = n.p == true; result})
var b by Delegates.vetoable(A(true), { pd, o, n -> result = n.p == true; result})
override fun box(): String {
val firstValue = A(true)
@@ -115,8 +115,8 @@ class TestMapPropertyString(): WithBox {
class TestMapValWithDefault(): WithBox {
val map = hashMapOf<String, String>()
val a: String by Delegates.mapVal(map, default = { ref, desc -> "aDefault" })
val b: String by FixedMapVal(map, default = { (ref: TestMapValWithDefault, desc: String) -> "bDefault" }, key = {"b"})
val c: String by FixedMapVal(map, default = { (ref: TestMapValWithDefault, desc: String) -> "cDefault" }, key = { desc -> desc.name })
val b: String by FixedMapVal(map, default = { ref: TestMapValWithDefault, desc: String -> "bDefault" }, key = {"b"})
val c: String by FixedMapVal(map, default = { ref: TestMapValWithDefault, desc: String -> "cDefault" }, key = { desc -> desc.name })
override fun box(): String {
if (a != "aDefault") return "fail at 'a'"
@@ -129,8 +129,8 @@ class TestMapValWithDefault(): WithBox {
class TestMapVarWithDefault(): WithBox {
val map = hashMapOf<String, Any?>()
var a: String by Delegates.mapVar(map, default = {ref, desc -> "aDefault" })
var b: String by FixedMapVar(map, default = {(ref: Any?, desc: String) -> "bDefault" }, key = {"b"})
var c: String by FixedMapVar(map, default = {(ref: Any?, desc: String) -> "cDefault" }, key = { desc -> desc.name })
var b: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "bDefault" }, key = {"b"})
var c: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "cDefault" }, key = { desc -> desc.name })
override fun box(): String {
if (a != "aDefault") return "fail at 'a'"
+4 -4
View File
@@ -290,7 +290,7 @@ class StringJVMTest {
test fun testReplaceAllClosure() {
val s = "test123zzz"
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"[" + mr.group() + "]"
}
assertEquals("test[123]zzz", result)
@@ -298,7 +298,7 @@ class StringJVMTest {
test fun testReplaceAllClosureAtStart() {
val s = "123zzz"
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"[" + mr.group() + "]"
}
assertEquals("[123]zzz", result)
@@ -306,7 +306,7 @@ class StringJVMTest {
test fun testReplaceAllClosureAtEnd() {
val s = "test123"
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"[" + mr.group() + "]"
}
assertEquals("test[123]", result)
@@ -314,7 +314,7 @@ class StringJVMTest {
test fun testReplaceAllClosureEmpty() {
val s = ""
val result = s.replaceAll("\\d+") { (mr) ->
val result = s.replaceAll("\\d+") { mr ->
"x"
}
assertEquals("", result)
+1 -1
View File
@@ -285,7 +285,7 @@ class StringTest {
)
val trimChars = charArray('-','=')
val trimPredicate = { (it: Char) -> it < '0' || it > '9' } // TODO: Use !it.isDigit when available in JS
val trimPredicate = { it: Char -> it < '0' || it > '9' } // TODO: Use !it.isDigit when available in JS
for (example in examplesForPredicate) {
assertEquals(example.trimStart(*trimChars).trimEnd(*trimChars), example.trim(*trimChars))
assertEquals(example.trimStart(trimPredicate).trimEnd(trimPredicate), example.trim(trimPredicate))