re-enabled compiling to JS test cases now we've fixed the compilation of the latest comparator based standard library code

This commit is contained in:
James Strachan
2012-06-29 23:13:05 +01:00
parent e06e5198ed
commit 63e0f169fc
9 changed files with 39 additions and 34 deletions
@@ -5,6 +5,7 @@ import java.util.Collection
import java.util.List
import java.util.AbstractList
import java.util.Iterator
import java.util.Comparator
/**
* Count the number of elements in collection.
@@ -71,19 +72,6 @@ public fun <T> java.lang.Iterable<T>.last() : T {
return last;
}
/**
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
*
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it._2}) returns list sorted by second element of tuple
*
* @includeFunctionBody ../../test/CollectionTest.kt sortBy
*/
public inline fun <in T, R: Comparable<in R>> java.lang.Iterable<T>.sortBy(f: (T) -> R): java.util.List<T> {
val sortedList = this.toList()
java.util.Collections.sort(sortedList, comparator {(x, y) -> f(x).compareTo(f(y))})
return sortedList
}
/**
* Checks if collection contains given item.
*
@@ -0,0 +1,27 @@
package kotlin
import java.util.AbstractList
import java.util.Collection
import java.util.Comparator
import java.util.Iterator
import java.util.List
// TODO this function is here as it breaks the JS compiler; lets move back to JLangIterablesSpecial when it works again :)
/**
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
*
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it._2}) returns list sorted by second element of tuple
*
* @includeFunctionBody ../../test/CollectionTest.kt sortBy
*/
public inline fun <in T, R: Comparable<in R>> java.lang.Iterable<T>.sortBy(f: (T) -> R): java.util.List<T> {
val sortedList = this.toList()
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
val xr = f(x)
val yr = f(y)
xr.compareTo(yr)
}
java.util.Collections.sort(sortedList, sortBy)
return sortedList
}