added JS support for toSet() and fixed issue with code generated array methods

This commit is contained in:
James Strachan
2012-06-23 07:49:15 +01:00
parent 4a4cf0467f
commit c8a1ffe813
25 changed files with 42 additions and 121 deletions
@@ -257,6 +257,9 @@ public inline fun <in T> Array<T>.toList() : List<T> = toCollection(ArrayList<T>
/** Copies all elements into a [[List] */
public inline fun <in T> Array<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[Set]] */
public inline fun <in T> Array<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun <in T> Array<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
@@ -276,9 +279,6 @@ public inline fun <in T> Array<T>.toSortedList(transform: fun(T) : java.lang.Com
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun <in T> Array<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/** Copies all elements into a [[SortedSet]] */
public inline fun <in T> Array<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -95,10 +95,6 @@ public inline fun <in T> Array<T?>?.requireNoNulls() : List<T> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun <T> Array<T>.drop(n: Int): List<T> {
fun countTo(n: Int): (T) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun <T> Array<T>.dropWhile(predicate: (T) -> Boolean): List<T> = d
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun <T> Array<T>.take(n: Int): List<T> {
fun countTo(n: Int): (T) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun BooleanArray.toList() : List<Boolean> = toCollection(ArrayLis
/** Copies all elements into a [[List] */
public inline fun BooleanArray.toCollection() : Collection<Boolean> = toCollection(ArrayList<Boolean>())
/** Copies all elements into a [[Set]] */
public inline fun BooleanArray.toSet() : Set<Boolean> = toCollection(HashSet<Boolean>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun BooleanArray.toSortedList(transform: fun(Boolean) : java.lang.Comparable<*>) : List<Boolean> {
@@ -276,9 +279,6 @@ public inline fun BooleanArray.toSortedList(transform: fun(Boolean) : java.lang
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun BooleanArray.toSet() : Set<Boolean> = toCollection(HashSet<Boolean>())
/** Copies all elements into a [[SortedSet]] */
public inline fun BooleanArray.toSortedSet() : SortedSet<Boolean> = toCollection(TreeSet<Boolean>())
@@ -95,10 +95,6 @@ public inline fun BooleanArray?.requireNoNulls() : List<Boolean> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun BooleanArray.drop(n: Int): List<Boolean> {
fun countTo(n: Int): (Boolean) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List<
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun BooleanArray.take(n: Int): List<Boolean> {
fun countTo(n: Int): (Boolean) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun ByteArray.toList() : List<Byte> = toCollection(ArrayList<Byte
/** Copies all elements into a [[List] */
public inline fun ByteArray.toCollection() : Collection<Byte> = toCollection(ArrayList<Byte>())
/** Copies all elements into a [[Set]] */
public inline fun ByteArray.toSet() : Set<Byte> = toCollection(HashSet<Byte>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun ByteArray.toSortedList(transform: fun(Byte) : java.lang.Comparable<*>) : List<Byte> {
@@ -276,9 +279,6 @@ public inline fun ByteArray.toSortedList(transform: fun(Byte) : java.lang.Compa
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun ByteArray.toSet() : Set<Byte> = toCollection(HashSet<Byte>())
/** Copies all elements into a [[SortedSet]] */
public inline fun ByteArray.toSortedSet() : SortedSet<Byte> = toCollection(TreeSet<Byte>())
@@ -95,10 +95,6 @@ public inline fun ByteArray?.requireNoNulls() : List<Byte> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun ByteArray.drop(n: Int): List<Byte> {
fun countTo(n: Int): (Byte) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List<Byte>
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun ByteArray.take(n: Int): List<Byte> {
fun countTo(n: Int): (Byte) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun CharArray.toList() : List<Char> = toCollection(ArrayList<Char
/** Copies all elements into a [[List] */
public inline fun CharArray.toCollection() : Collection<Char> = toCollection(ArrayList<Char>())
/** Copies all elements into a [[Set]] */
public inline fun CharArray.toSet() : Set<Char> = toCollection(HashSet<Char>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun CharArray.toSortedList(transform: fun(Char) : java.lang.Comparable<*>) : List<Char> {
@@ -276,9 +279,6 @@ public inline fun CharArray.toSortedList(transform: fun(Char) : java.lang.Compa
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun CharArray.toSet() : Set<Char> = toCollection(HashSet<Char>())
/** Copies all elements into a [[SortedSet]] */
public inline fun CharArray.toSortedSet() : SortedSet<Char> = toCollection(TreeSet<Char>())
@@ -95,10 +95,6 @@ public inline fun CharArray?.requireNoNulls() : List<Char> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun CharArray.drop(n: Int): List<Char> {
fun countTo(n: Int): (Char) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun CharArray.dropWhile(predicate: (Char) -> Boolean): List<Char>
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun CharArray.take(n: Int): List<Char> {
fun countTo(n: Int): (Char) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun DoubleArray.toList() : List<Double> = toCollection(ArrayList<
/** Copies all elements into a [[List] */
public inline fun DoubleArray.toCollection() : Collection<Double> = toCollection(ArrayList<Double>())
/** Copies all elements into a [[Set]] */
public inline fun DoubleArray.toSet() : Set<Double> = toCollection(HashSet<Double>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun DoubleArray.toSortedList(transform: fun(Double) : java.lang.Comparable<*>) : List<Double> {
@@ -276,9 +279,6 @@ public inline fun DoubleArray.toSortedList(transform: fun(Double) : java.lang.C
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun DoubleArray.toSet() : Set<Double> = toCollection(HashSet<Double>())
/** Copies all elements into a [[SortedSet]] */
public inline fun DoubleArray.toSortedSet() : SortedSet<Double> = toCollection(TreeSet<Double>())
@@ -95,10 +95,6 @@ public inline fun DoubleArray?.requireNoNulls() : List<Double> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun DoubleArray.drop(n: Int): List<Double> {
fun countTo(n: Int): (Double) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List<Do
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun DoubleArray.take(n: Int): List<Double> {
fun countTo(n: Int): (Double) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun FloatArray.toList() : List<Float> = toCollection(ArrayList<Fl
/** Copies all elements into a [[List] */
public inline fun FloatArray.toCollection() : Collection<Float> = toCollection(ArrayList<Float>())
/** Copies all elements into a [[Set]] */
public inline fun FloatArray.toSet() : Set<Float> = toCollection(HashSet<Float>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun FloatArray.toSortedList(transform: fun(Float) : java.lang.Comparable<*>) : List<Float> {
@@ -276,9 +279,6 @@ public inline fun FloatArray.toSortedList(transform: fun(Float) : java.lang.Com
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun FloatArray.toSet() : Set<Float> = toCollection(HashSet<Float>())
/** Copies all elements into a [[SortedSet]] */
public inline fun FloatArray.toSortedSet() : SortedSet<Float> = toCollection(TreeSet<Float>())
@@ -95,10 +95,6 @@ public inline fun FloatArray?.requireNoNulls() : List<Float> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun FloatArray.drop(n: Int): List<Float> {
fun countTo(n: Int): (Float) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List<Floa
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun FloatArray.take(n: Int): List<Float> {
fun countTo(n: Int): (Float) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun IntArray.toList() : List<Int> = toCollection(ArrayList<Int>()
/** Copies all elements into a [[List] */
public inline fun IntArray.toCollection() : Collection<Int> = toCollection(ArrayList<Int>())
/** Copies all elements into a [[Set]] */
public inline fun IntArray.toSet() : Set<Int> = toCollection(HashSet<Int>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun IntArray.toSortedList(transform: fun(Int) : java.lang.Comparable<*>) : List<Int> {
@@ -276,9 +279,6 @@ public inline fun IntArray.toSortedList(transform: fun(Int) : java.lang.Compara
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun IntArray.toSet() : Set<Int> = toCollection(HashSet<Int>())
/** Copies all elements into a [[SortedSet]] */
public inline fun IntArray.toSortedSet() : SortedSet<Int> = toCollection(TreeSet<Int>())
@@ -95,10 +95,6 @@ public inline fun IntArray?.requireNoNulls() : List<Int> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun IntArray.drop(n: Int): List<Int> {
fun countTo(n: Int): (Int) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List<Int> = d
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun IntArray.take(n: Int): List<Int> {
fun countTo(n: Int): (Int) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -255,6 +255,9 @@ public inline fun <in T> java.util.Iterator<T>.toList() : List<T> = toCollection
/** Copies all elements into a [[List] */
public inline fun <in T> java.util.Iterator<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[Set]] */
public inline fun <in T> java.util.Iterator<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun <in T> java.util.Iterator<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
@@ -274,9 +277,6 @@ public inline fun <in T> java.util.Iterator<T>.toSortedList(transform: fun(T) :
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun <in T> java.util.Iterator<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/** Copies all elements into a [[SortedSet]] */
public inline fun <in T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -257,6 +257,9 @@ public inline fun LongArray.toList() : List<Long> = toCollection(ArrayList<Long
/** Copies all elements into a [[List] */
public inline fun LongArray.toCollection() : Collection<Long> = toCollection(ArrayList<Long>())
/** Copies all elements into a [[Set]] */
public inline fun LongArray.toSet() : Set<Long> = toCollection(HashSet<Long>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun LongArray.toSortedList(transform: fun(Long) : java.lang.Comparable<*>) : List<Long> {
@@ -276,9 +279,6 @@ public inline fun LongArray.toSortedList(transform: fun(Long) : java.lang.Compa
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun LongArray.toSet() : Set<Long> = toCollection(HashSet<Long>())
/** Copies all elements into a [[SortedSet]] */
public inline fun LongArray.toSortedSet() : SortedSet<Long> = toCollection(TreeSet<Long>())
@@ -95,10 +95,6 @@ public inline fun LongArray?.requireNoNulls() : List<Long> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun LongArray.drop(n: Int): List<Long> {
fun countTo(n: Int): (Long) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List<Long>
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun LongArray.take(n: Int): List<Long> {
fun countTo(n: Int): (Long) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun ShortArray.toList() : List<Short> = toCollection(ArrayList<Sh
/** Copies all elements into a [[List] */
public inline fun ShortArray.toCollection() : Collection<Short> = toCollection(ArrayList<Short>())
/** Copies all elements into a [[Set]] */
public inline fun ShortArray.toSet() : Set<Short> = toCollection(HashSet<Short>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun ShortArray.toSortedList(transform: fun(Short) : java.lang.Comparable<*>) : List<Short> {
@@ -276,9 +279,6 @@ public inline fun ShortArray.toSortedList(transform: fun(Short) : java.lang.Com
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun ShortArray.toSet() : Set<Short> = toCollection(HashSet<Short>())
/** Copies all elements into a [[SortedSet]] */
public inline fun ShortArray.toSortedSet() : SortedSet<Short> = toCollection(TreeSet<Short>())
@@ -95,10 +95,6 @@ public inline fun ShortArray?.requireNoNulls() : List<Short> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun ShortArray.drop(n: Int): List<Short> {
fun countTo(n: Int): (Short) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List<Shor
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun ShortArray.take(n: Int): List<Short> {
fun countTo(n: Int): (Short) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}
@@ -257,6 +257,9 @@ public inline fun <in T> Iterable<T>.toList() : List<T> = toCollection(ArrayList
/** Copies all elements into a [[List] */
public inline fun <in T> Iterable<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[Set]] */
public inline fun <in T> Iterable<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun <in T> Iterable<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
@@ -276,9 +279,6 @@ public inline fun <in T> Iterable<T>.toSortedList(transform: fun(T) : java.lang.
import java.util.*
/** Copies all elements into a [[Set]] */
public inline fun <in T> Iterable<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/** Copies all elements into a [[SortedSet]] */
public inline fun <in T> Iterable<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -95,10 +95,6 @@ public inline fun <in T> Iterable<T?>?.requireNoNulls() : List<T> {
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun <T> Iterable<T>.drop(n: Int): List<T> {
fun countTo(n: Int): (T) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return dropWhile(countTo(n))
}
@@ -115,10 +111,6 @@ public inline fun <T> Iterable<T>.dropWhile(predicate: (T) -> Boolean): List<T>
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun <T> Iterable<T>.take(n: Int): List<T> {
fun countTo(n: Int): (T) -> Boolean {
var count = 0
return { ++count; count <= n }
}
return takeWhile(countTo(n))
}