GreatSyntacticShift: Codegen testdata fixed

This commit is contained in:
Andrey Breslav
2011-12-20 22:56:13 +04:00
parent 41fd43b5e5
commit 6aad3b2662
67 changed files with 151 additions and 151 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
namespace foo;
package foo;
fun main(args : Array<String>) {
@@ -1,7 +1,7 @@
fun box() : String {
return apply( "OK", {(arg: String) => arg } )
return apply( "OK", {(arg: String) -> arg } )
}
fun apply(arg : String, f : fun (p:String) : String) : String {
fun apply(arg : String, f : (p:String) -> String) : String {
return f(arg)
}
@@ -1,7 +1,7 @@
fun box() : String {
return if (apply( 5, {(arg: Int) => arg + 13 } ) == 18) "OK" else "fail"
return if (apply( 5, {(arg: Int) -> arg + 13 } ) == 18) "OK" else "fail"
}
fun apply(arg : Int, f : fun (p:Int) : Int) : Int {
fun apply(arg : Int, f : (p:Int) -> Int) : Int {
return f(arg)
}
@@ -3,6 +3,6 @@ fun box() : String {
return if (sum(200, { val ff = {cl}; ff() }) == 239) "OK" else "FAIL"
}
fun sum(arg:Int, f : fun () : Int) : Int {
fun sum(arg:Int, f : () -> Int) : Int {
return arg + f()
}
@@ -3,6 +3,6 @@ fun box() : String {
return if (sum(200, { val m = { val r = { cl }; r() }; m() }) == 239) "OK" else "FAIL"
}
fun sum(arg:Int, f : fun () : Int) : Int {
fun sum(arg:Int, f : () -> Int) : Int {
return arg + f()
}
@@ -1,10 +1,10 @@
class Point(val x:Int, val y:Int) {
fun mul() : fun (scalar:Int):Point {
return { (scalar:Int):Point => Point(x * scalar, y * scalar) }
fun mul() : (scalar:Int)->Point {
return { (scalar:Int):Point -> Point(x * scalar, y * scalar) }
}
}
val m = Point(2, 3).mul() : fun (scalar:Int):Point
val m = Point(2, 3).mul() : (scalar:Int)->Point
fun box() : String {
val answer = m(5)
@@ -1,13 +1,13 @@
class Point(val x : Int, val y : Int)
fun box() : String {
val answer = apply(Point(3, 5), { Point.(scalar : Int) : Point =>
val answer = apply(Point(3, 5), { Point.(scalar : Int) : Point ->
Point(x * scalar, y * scalar)
})
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
}
fun apply(arg:Point, f : fun Point.(scalar : Int) : Point) : Point {
fun apply(arg:Point, f : Point.(scalar : Int) -> Point) : Point {
return arg.f(2)
}
@@ -2,6 +2,6 @@ fun box() : String {
return invoker( {"OK"} )
}
fun invoker(gen : fun () : String) : String {
fun invoker(gen : () -> String) : String {
return gen()
}
@@ -2,6 +2,6 @@ fun box() : String {
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
}
fun int_invoker(gen : fun () : Int) : Int {
fun int_invoker(gen : () -> Int) : Int {
return gen()
}
@@ -1,7 +1,7 @@
import java.util.concurrent.*
import java.util.concurrent.atomic.*
fun thread(block: fun():Unit ) {
fun thread(block: ()->Unit ) {
val thread = object: Thread() {
override fun run() {
block()
@@ -1,6 +1,6 @@
import java.util.*
fun <T> ArrayList<T>.findAll(predicate: fun (T) : Boolean): ArrayList<T> {
fun <T> ArrayList<T>.findAll(predicate: (T) -> Boolean): ArrayList<T> {
val result = ArrayList<T>()
for(val t in this) {
if (predicate(t)) result.add(t)
@@ -16,6 +16,6 @@ fun box(): String {
list.add("Moscow")
list.add("Munich")
val m: ArrayList<String> = list.findAll<String>({(name: String) => name.startsWith("M")})
val m: ArrayList<String> = list.findAll<String>({(name: String) -> name.startsWith("M")})
return if (m.size() == 2) "OK" else "fail"
}
@@ -2,7 +2,7 @@ fun <T> T.mustBe(t : T) {
assert("$this must be $t") {this == t}
}
inline fun assert(message : String, condition : fun() : Boolean) {
inline fun assert(message : String, condition : () -> Boolean) {
if (!condition())
throw AssertionError(message)
}
@@ -3,7 +3,7 @@ class Request(val path: String) {
}
class Handler() {
fun Int.times(op: fun(): Unit) {
fun Int.times(op: ()-> Unit) {
for(i in 0..this)
op()
}
@@ -8,7 +8,7 @@ fun StringBuilder.takeFirst(): Char {
fun foo(expr: StringBuilder): Int {
val c = expr.takeFirst()
when(c) {
0.chr => throw Exception("zero")
else => throw Exception("nonzero" + c)
0.chr -> throw Exception("zero")
else -> throw Exception("nonzero" + c)
}
}
@@ -5,7 +5,7 @@ fun reformat(
divideByCamelHumps : Boolean = true,
wordSeparator : String = " "
) =
(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
#(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
trait A {
fun bar2(arg: Int = 239) : Int
@@ -38,7 +38,7 @@ class C() : B() {
fun <T> T.toPrefixedString(prefix: String = "", suffix: String="") = prefix + (this as java.lang.Object).toString() + suffix
fun box() : String {
val expected = (true, true, true, " ")
val expected = #(true, true, true, " ")
if("mama".toPrefixedString(suffix="321", prefix="papa") != "papamama321") return "fail"
if("mama".toPrefixedString(prefix="papa") != "papamama") return "fail"
@@ -1,24 +1,24 @@
fun Any.foo1() : fun(): String {
fun Any.foo1() : ()-> String {
return { "239" + this }
}
fun Int.foo2() : fun(i : Int) : Int {
return { x => x + this }
fun Int.foo2() : (i : Int) -> Int {
return { x -> x + this }
}
fun fooT1<T>(t : T) = { t.toString() }
fun fooT2<T>(t: T) = { (x:T) => t.toString() + x.toString() }
fun fooT2<T>(t: T) = { (x:T) -> t.toString() + x.toString() }
fun box() : String {
if( (10.foo1())() != "23910") return "foo1 fail"
if( (10.foo2())(1) != 11 ) return "foo2 fail"
if(1.{Int.() => this + 1}() != 2) return "test 3 failed";
if(1.{Int.() -> this + 1}() != 2) return "test 3 failed";
if( {1}() != 1) return "test 4 failed";
if( {(x : Int) => x}(1) != 1) return "test 5 failed";
if( 1.{Int.(x : Int) => x + this}(1) != 2) return "test 6 failed";
if( 1.({Int.() => this})() != 1) return "test 7 failed";
if( {(x : Int) -> x}(1) != 1) return "test 5 failed";
if( 1.{Int.(x : Int) -> x + this}(1) != 2) return "test 6 failed";
if( 1.({Int.() -> this})() != 1) return "test 7 failed";
if( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
if( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
return "OK"
@@ -1,6 +1,6 @@
fun loop(var times : Int) {
while(times > 0) {
val u : fun(value : Int) : Unit = {
val u : (value : Int) -> Unit = {
System.out?.println(it)
}
u(times--)
@@ -1,5 +1,5 @@
class X<T> () {
fun getTypeChecker() = { (a : Any) => a is T }
fun getTypeChecker() = { (a : Any) -> a is T }
}
fun box() : String {
@@ -1,4 +1,4 @@
namespace Foo {
package Foo {
fun bar() = 610
}
@@ -1,4 +1,4 @@
fun isZero(x: Int) = when(x) {
0 => true
else => false
0 -> true
else -> false
}
@@ -1,3 +1,3 @@
fun isZero(x: Int) = when(x) {
0 => true
0 -> true
}
@@ -1,7 +1,7 @@
fun typeName(a: Any?) : String {
return when(a) {
is java.util.ArrayList<*> => "array list"
else => "no idea"
is java.util.ArrayList<*> -> "array list"
else -> "no idea"
}
}
@@ -1,4 +1,4 @@
fun isString(x: Any) = when(x) {
is String => "string"
else => "something"
is String -> "string"
else -> "something"
}
@@ -3,9 +3,9 @@ fun isDigit(a: Int) : String {
aa.add(239)
return when(a) {
in aa => "array list"
in 0..9 => "digit"
!in 0..100 => "not small"
else => "something"
in aa -> "array list"
in 0..9 -> "digit"
!in 0..100 -> "not small"
else -> "something"
}
}
@@ -1,4 +1,4 @@
fun isDigit(a: Char) = when(a) {
in '0'..'9' => "digit"
else => "something"
in '0'..'9' -> "digit"
else -> "something"
}
@@ -1,11 +1,11 @@
fun main(args: Array<String>?) {
val y: Unit = () //do not compile
val y: Unit = #() //do not compile
A<Unit>() //do not compile
C<Unit>(()) //do not compile
C<Unit>(#()) //do not compile
//do not compile
System.out?.println(fff<Unit>(())) //do not compile
System.out?.println(fff<Unit>(#())) //do not compile
System.out?.println(id<Unit>(y)) //do not compile
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0,{0}),{(e : Int) : Unit => }))) //do not compile
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0,{0}),{(e : Int) : Unit -> }))) //do not compile
}
class A<T>()
@@ -17,13 +17,13 @@ fun <T> fff(x: T) : T { return x }
fun <T> id(value: T): T = value
fun foreach(array: Array<Int>?, action: fun(Int): Unit) {
fun foreach(array: Array<Int>?, action: (Int)-> Unit) {
for (el in array) {
action(el) //exception through compilation (see below)
}
}
fun almostFilter(array: Array<Int>, action: fun(Int): Int) {
fun almostFilter(array: Array<Int>, action: (Int)-> Int) {
for (el in array) {
action(el)
}
@@ -34,8 +34,8 @@ fun box() : String {
a[0] = 0
a[1] = 1
a[2] = 2
foreach(a, { (el : Int) : Unit => System.out?.println(el) })
almostFilter(a, { (el : Int) : Int => el })
foreach(a, { (el : Int) : Unit -> System.out?.println(el) })
almostFilter(a, { (el : Int) : Int -> el })
main(null)
return "OK"
}
@@ -1,4 +1,4 @@
namespace x
package x
class Outer() {
class object {
@@ -1,4 +1,4 @@
namespace test
package test
class List<T>(len: Int) {
val a : Array<T?> = Array<T?>(len)
@@ -1,12 +1,12 @@
import java.util.ArrayList
fun launch(f : fun() : Unit) {
fun launch(f : () -> Unit) {
f()
}
fun box(): String {
val list = ArrayList<Int>()
val foo : fun() : Unit = {
val foo : () -> Unit = {
list.add(2) //first exception
}
foo()
@@ -27,7 +27,7 @@ fun t1() : Boolean {
x = x + "45" + y
x = x.substring(3)
x += "aaa"
()
#()
}
foo()
@@ -43,7 +43,7 @@ fun t2() : Boolean {
x = x + 5 + y
x += 5
x++
()
#()
}
foo()
x -= 55
@@ -55,7 +55,7 @@ fun t3() : Boolean {
var x = true
val foo = {
x = false
()
#()
}
foo()
return !x
@@ -67,7 +67,7 @@ fun t4() : Boolean {
val foo = {
x = x + 200.flt + y
x += 18
()
#()
}
foo()
System.out?.println(x)
@@ -80,7 +80,7 @@ fun t5() : Boolean {
val foo = {
x = x + 200.dbl + y
x -= 22
()
#()
}
foo()
System.out?.println(x)
@@ -94,7 +94,7 @@ fun t6() : Boolean {
x = (x + 20.byt + y).byt
x += 2
x--
()
#()
}
foo()
System.out?.println(x)
@@ -105,7 +105,7 @@ fun t7() : Boolean {
var x : Char = 'a'
val foo = {
x = 'b'
()
#()
}
foo()
System.out?.println(x)
@@ -117,10 +117,10 @@ fun t8() : Boolean {
val foo = {
val bar = {
x = 30.sht
()
#()
}
bar()
()
#()
}
foo()
return x == 30.sht
@@ -1,6 +1,6 @@
fun Any.with(operation : fun Any.() : Any) = operation().toString()
fun Any.with(operation : Any.() -> Any) = operation().toString()
val f = { (a : Int) :Unit => }
val f = { (a : Int) :Unit -> }
fun box () : String {
return if(20.with {
@@ -1,4 +1,4 @@
namespace mult_constructors_3_bug
package mult_constructors_3_bug
public open class Identifier() {
private var myNullable : Boolean = true
@@ -1,4 +1,4 @@
namespace one_extends_base
package one_extends_base
open class Base<T>(name : T?) {
var myName : T?
@@ -1,4 +1,4 @@
namespace mask
package mask
import std.io.*
import java.io.*
@@ -52,7 +52,7 @@ class Luhny() {
fun check() {
if (digits.size() < 14) return
print("check")
val sum = digits.sum { i, d =>
val sum = digits.sum { i, d ->
// println("$i -> $d")
if (i % 2 == digits.size()) {
val f = d * 2 / 10
@@ -94,12 +94,12 @@ class Luhny() {
}
}
fun <T> T.pr(f : fun(T) : Unit) : T {
fun <T> T.pr(f : (T) -> Unit) : T {
f(this)
return this
}
fun LinkedList<Int>.sum(f : fun(Int, Int ): Int): Int {
fun LinkedList<Int>.sum(f : (Int, Int )-> Int): Int {
var sum = 0
for (i in 1..size()) {
val j = size() - i
@@ -120,7 +120,7 @@ fun LinkedList<Int>.sum(f : fun(Int, Int ): Int): Int {
fun Char.isDigit() = Character.isDigit(this)
fun Reader.forEachChar(body : fun(Char) : Unit) {
fun Reader.forEachChar(body : (Char) -> Unit) {
do {
var i = read();
if (i == -1) break
@@ -1,4 +1,4 @@
namespace mask
package mask
import std.io.*
import java.io.*
@@ -46,7 +46,7 @@ class Luhny() {
private fun check() {
val size = digits.size()
if (size < 14) return
val sum = digits.sum {i, d =>
val sum = digits.sum {i, d ->
if (i % 2 == size % 2) double(d) else d
}
// var sum = 0
@@ -89,7 +89,7 @@ class Luhny() {
fun Char.isDigit() = Character.isDigit(this)
fun java.lang.Iterable<Int>.sum(f : fun(index : Int, value : Int) : Int) : Int {
fun java.lang.Iterable<Int>.sum(f : (index : Int, value : Int) -> Int) : Int {
var sum = 0
var i = 0
for (d in this) {
@@ -99,7 +99,7 @@ fun java.lang.Iterable<Int>.sum(f : fun(index : Int, value : Int) : Int) : Int {
return sum
}
fun Reader.forEachChar(body : fun(Char) : Unit) {
fun Reader.forEachChar(body : (Char) -> Unit) {
do {
var i = read();
if (i == -1) break
@@ -1,4 +1,4 @@
namespace mask
package mask
import std.io.*
import java.io.*
@@ -50,7 +50,7 @@ class Luhny() {
fun check() {
if (digits.size() < 14) return
val sum = digits.sum { i, d =>
val sum = digits.sum { i, d ->
if (i % 2 != 0)
d * 2 / 10 + d * 2 % 10
else d
@@ -85,7 +85,7 @@ class Luhny() {
}
}
fun LinkedList<Int>.sum(f : fun(Int, Int) : Int) : Int {
fun LinkedList<Int>.sum(f : (Int, Int) -> Int) : Int {
var sum = 0
var i = 0
for (d in backwards()) {
@@ -136,7 +136,7 @@ fun Char.isDigit() = Character.isDigit(this)
// fun clear() {}
//}
fun Reader.forEachChar(body : fun(Char) : Unit) {
fun Reader.forEachChar(body : (Char) -> Unit) {
do {
var i = read();
if (i == -1) break
@@ -1,4 +1,4 @@
namespace while_bug_1
package while_bug_1
import java.io.*
@@ -1,4 +1,4 @@
namespace whats.the.difference
package whats.the.difference
import java.util.HashSet
@@ -1,4 +1,4 @@
namespace array_test
package array_test
fun box() : String {
var array : IntArray? = IntArray(10)
@@ -1,4 +1,4 @@
namespace name
package name
class Test() {
var i = 5
@@ -1,4 +1,4 @@
namespace demo
package demo
public open class Identifier<T>(myName : T?, myHasDollar : Boolean) {
{
@@ -1,8 +1,8 @@
fun escapeChar(c : Char) : String? = when (c) {
'\\' => "\\\\"
'\n' => "\\n"
'"' => "\\\""
else => String.valueOf(c)
'\\' -> "\\\\"
'\n' -> "\\n"
'"' -> "\\\""
else -> String.valueOf(c)
}
fun String.escape(i : Int = 0, result : String = "") : String =
@@ -1,4 +1,4 @@
namespace org2
package org2
enum class Test {
A
@@ -1,6 +1,6 @@
class List<T>(val head: T, val tail: List<T>? = null)
fun <T> List<T>.mapHead(f: fun(T): T): List<T> = List<T>(f(head), null)
fun <T> List<T>.mapHead(f: (T)-> T): List<T> = List<T>(f(head), null)
fun box() : String {
val a: Int = List<Int>(1).mapHead{it * 2}.head
@@ -1,4 +1,4 @@
namespace demo_range
package demo_range
fun Int?.rangeTo(other : Int?) : IntRange = this.sure().rangeTo(other.sure())
@@ -1,4 +1,4 @@
namespace bitwise_demo
package bitwise_demo
fun Long?.shl(bits : Int?) : Long = this.sure().shl(bits.sure())
@@ -1,4 +1,4 @@
namespace demo_range
package demo_range
fun Int?.plus() : Int = this.sure().plus()
fun Int?.dec() : Int = this.sure().dec()
@@ -1,4 +1,4 @@
namespace demo_long
package demo_long
fun Long?.inv() : Long = this.sure().inv()
@@ -1,10 +1,10 @@
namespace w_range
package w_range
fun box() : String {
var i = 0
when (i) {
1 => i--
else => { i = 2 }
1 -> i--
else -> { i = 2 }
}
System.out?.println(i)
return "OK"
@@ -1,18 +1,18 @@
namespace demo2
package demo2
fun print(o : Any?) {}
fun test(i : Int) {
var monthString : String? = "<empty>"
when (i) {
1 => {
1 -> {
print(1)
print(2)
print(3)
print(4)
print(5)
}
else => {
else -> {
monthString = "Invalid month"
}
}
@@ -1,18 +1,18 @@
namespace demo2
package demo2
fun print(o : Any?) {}
fun test(i : Int) {
var monthString : String? = "<empty>"
when (i) {
1 => {
1 -> {
print(1)
print(2)
print(3)
print(4)
print(5)
}
else => {
else -> {
monthString = "Invalid month"
}
}
@@ -1,7 +1,7 @@
class A() {
var x : Int = 0
var z = { () =>
var z = { () ->
x++
}
}
@@ -1,4 +1,4 @@
namespace foo
package foo
import java.util.*;
@@ -1,4 +1,4 @@
namespace demo
package demo
fun box() : String {
var res : Boolean = true
+1 -1
View File
@@ -36,7 +36,7 @@ trait WriteOnlyArray<in T> : ISized {
}
}
class MutableArray<T>(length: Int, init : fun(Int) : T) : ReadOnlyArray<T>, WriteOnlyArray<T> {
class MutableArray<T>(length: Int, init : (Int) -> T) : ReadOnlyArray<T>, WriteOnlyArray<T> {
private val array = Array<T>(length, init)
override fun get(index : Int) : T = array[index]
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
fun test() : Int {
foo(1)
val a : fun() : Unit = {
val a : () -> Unit = {
foo(1)
}
return 1 - "1"
@@ -485,7 +485,7 @@ public class NamespaceGenTest extends CodegenTestCase {
}
public void testTupleLiteral() throws Exception {
loadText("fun foo() = (1, \"foo\")");
loadText("fun foo() = #(1, \"foo\")");
// System.out.println(generateToText());
final Method main = generateFunction("foo");
Tuple2 tuple2 = (Tuple2) main.invoke(null);
@@ -494,7 +494,7 @@ public class NamespaceGenTest extends CodegenTestCase {
}
public void testParametrizedTupleLiteral() throws Exception {
loadText("fun <E,D> E.foo(extra: java.util.List<D>) = (1, \"foo\", this, extra)");
loadText("fun <E,D> E.foo(extra: java.util.List<D>) = #(1, \"foo\", this, extra)");
// System.out.println(generateToText());
final Method main = generateFunction();
Tuple4 tuple4 = (Tuple4) main.invoke(null, "aaa", TypeInfo.STRING_TYPE_INFO, TypeInfo.INT_TYPE_INFO, Arrays.asList(10));
@@ -74,19 +74,19 @@ public class PatternMatchingTest extends CodegenTestCase {
}
public void testWildcardPattern() throws Exception {
loadText("fun foo(x: String) = when(x) { is * => \"something\" }");
loadText("fun foo(x: String) = when(x) { is * -> \"something\" }");
Method foo = generateFunction();
assertEquals("something", foo.invoke(null, ""));
}
public void testNoReturnType() throws Exception {
loadText("fun foo(x: String) = when(x) { is * => \"x\" }");
loadText("fun foo(x: String) = when(x) { is * -> \"x\" }");
Method foo = generateFunction();
assertEquals("x", foo.invoke(null, ""));
}
public void testTuplePattern() throws Exception {
loadText("fun foo(x: (Any, Any)) = when(x) { is (1,2) => \"one,two\"; else => \"something\" }");
loadText("fun foo(x: (Any, Any)) = when(x) { is #(1,2) -> \"one,two\"; else -> \"something\" }");
Method foo = generateFunction();
final Object result;
try {
@@ -118,14 +118,14 @@ public class PatternMatchingTest extends CodegenTestCase {
}
public void testNames() throws Exception {
loadText("fun foo(x: (Any, Any)) = when(x) { is (val a is String, *) => a; else => \"something\" }");
loadText("fun foo(x: #(Any, Any)) = when(x) { is #(val a is String, *) -> a; else -> \"something\" }");
Method foo = generateFunction();
assertEquals("JetBrains", foo.invoke(null, new Tuple2<String, String>(null, "JetBrains", "s.r.o.")));
assertEquals("something", foo.invoke(null, new Tuple2<Integer, Integer>(null, 1, 2)));
}
public void testMultipleConditions() throws Exception {
loadText("fun foo(x: Any) = when(x) { is 0, 1 => \"bit\"; else => \"something\" }");
loadText("fun foo(x: Any) = when(x) { is 0, 1 -> \"bit\"; else -> \"something\" }");
Method foo = generateFunction();
assertEquals("bit", foo.invoke(null, 0));
assertEquals("bit", foo.invoke(null, 1));
+1 -1
View File
@@ -1,4 +1,4 @@
namespace std
package std
import java.io.ByteArrayInputStream
+6 -6
View File
@@ -1,4 +1,4 @@
namespace std
package std
import java.util.*
import java.lang.Iterable
@@ -6,7 +6,7 @@ import java.lang.Iterable
/*
Filters given iterator
*/
inline fun <T> java.util.Iterator<T>.filter(f: fun(T): Boolean) : java.util.Iterator<T> = FilterIterator<T>(this, f)
inline fun <T> java.util.Iterator<T>.filter(f: (T)-> Boolean) : java.util.Iterator<T> = FilterIterator<T>(this, f)
/*
Adds filtered elements in to given container
@@ -28,15 +28,15 @@ Create iterator filtering given java.lang.Iterable
inline fun <T> java.lang.Iterable<T>.filter(f: fun(T): Boolean) : java.util.Iterator<T> = (iterator() as java.util.Iterator<T>).filter(f)
*/
private class FilterIterator<T>(val original: java.util.Iterator<T>, val filter: fun(T): Boolean) : java.util.Iterator<T> {
private class FilterIterator<T>(val original: java.util.Iterator<T>, val filter: (T)-> Boolean) : java.util.Iterator<T> {
var state = 0
var nextElement: T? = null
override fun hasNext(): Boolean =
when(state) {
1 => true // checked and next present
2 => false // checked and next not present
else => {
1 -> true // checked and next present
2 -> false // checked and next not present
else -> {
while(original.hasNext()) {
val candidate = original.next()
if((filter)(candidate)) {
+1 -1
View File
@@ -1,4 +1,4 @@
namespace std.util
package std.util
import java.util.*
import java.util.Iterator
+2 -2
View File
@@ -1,6 +1,6 @@
namespace std
package std
namespace io {
package io {
import java.io.*
import java.nio.charset.*
+11 -11
View File
@@ -1,4 +1,4 @@
namespace std.util
package std.util
import java.util.*
@@ -20,7 +20,7 @@ inline fun linkedList<T>(vararg values: T) : LinkedList<T> = values.to(LinkedLi
inline fun hashSet<T>(vararg values: T) : HashSet<T> = values.to(HashSet<T>(values.size))
/** Returns true if any elements in the collection match the given predicate */
inline fun <T> java.lang.Iterable<T>.any(predicate: fun(T): Boolean) : Boolean {
inline fun <T> java.lang.Iterable<T>.any(predicate: (T)-> Boolean) : Boolean {
for (elem in this) {
if (predicate(elem)) {
return true
@@ -30,7 +30,7 @@ inline fun <T> java.lang.Iterable<T>.any(predicate: fun(T): Boolean) : Boolean {
}
/** Returns true if all elements in the collection match the given predicate */
inline fun <T> java.lang.Iterable<T>.all(predicate: fun(T): Boolean) : Boolean {
inline fun <T> java.lang.Iterable<T>.all(predicate: (T)-> Boolean) : Boolean {
for (elem in this) {
if (!predicate(elem)) {
return false
@@ -40,7 +40,7 @@ inline fun <T> java.lang.Iterable<T>.all(predicate: fun(T): Boolean) : Boolean {
}
/** Returns the first item in the collection which matches the given predicate or null if none matched */
inline fun <T> java.lang.Iterable<T>.find(predicate: fun(T): Boolean) : T? {
inline fun <T> java.lang.Iterable<T>.find(predicate: (T)-> Boolean) : T? {
for (elem in this) {
if (predicate(elem))
return elem
@@ -49,7 +49,7 @@ inline fun <T> java.lang.Iterable<T>.find(predicate: fun(T): Boolean) : T? {
}
/** Returns a new collection containing all elements in this collection which match the given predicate */
inline fun <T> java.lang.Iterable<T>.filter(result: Collection<T> = ArrayList<T>(), predicate: fun(T): Boolean) : Collection<T> {
inline fun <T> java.lang.Iterable<T>.filter(result: Collection<T> = ArrayList<T>(), predicate: (T)-> Boolean) : Collection<T> {
for (elem in this) {
if (predicate(elem))
result.add(elem)
@@ -61,7 +61,7 @@ inline fun <T> java.lang.Iterable<T>.filter(result: Collection<T> = ArrayList<T>
* Returns the result of transforming each item in the collection to a one or more values which
* are concatenated together into a single collection
*/
inline fun <T, out R> java.lang.Iterable<T>.flatMap(result: Collection<R> = ArrayList<R>(), transform: fun(T): Collection<R>) : Collection<R> {
inline fun <T, out R> java.lang.Iterable<T>.flatMap(result: Collection<R> = ArrayList<R>(), transform: (T)-> Collection<R>) : Collection<R> {
for (elem in this) {
val coll = transform(elem)
if (coll != null) {
@@ -74,7 +74,7 @@ inline fun <T, out R> java.lang.Iterable<T>.flatMap(result: Collection<R> = Arra
}
/** Performs the given operation on each element inside the collection */
inline fun <T> java.lang.Iterable<T>.foreach(operation: fun(element: T) : Unit) {
inline fun <T> java.lang.Iterable<T>.foreach(operation: (element: T) -> Unit) {
for (elem in this)
operation(elem)
}
@@ -95,14 +95,14 @@ inline fun <T> java.lang.Iterable<T>.join(separator: String, prefix: String = ""
}
/** Returns a new collection containing the results of applying the given function to each element in this collection */
inline fun <T, R> java.lang.Iterable<T>.map(result: Collection<R> = ArrayList<R>(), transform : fun(T) : R) : Collection<R> {
inline fun <T, R> java.lang.Iterable<T>.map(result: Collection<R> = ArrayList<R>(), transform : (T) -> R) : Collection<R> {
for (item in this)
result.add(transform(item))
return result
}
/** Returns a new collection containing the results of applying the given function to each element in this collection */
inline fun <T, R> java.util.Collection<T>.map(result: Collection<R> = ArrayList<R>(this.size), transform : fun(T) : R) : Collection<R> {
inline fun <T, R> java.util.Collection<T>.map(result: Collection<R> = ArrayList<R>(this.size), transform : (T) -> R) : Collection<R> {
for (item in this)
result.add(transform(item))
return result
@@ -211,7 +211,7 @@ val Map<*,*>.empty : Boolean
*/
/** Returns the value for the given key or returns the result of the defaultValue function if there was no entry for the given key */
inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: fun(): V) : V {
inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V {
val current = this.get(key)
if (current != null) {
return current
@@ -221,7 +221,7 @@ inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: fun(): V) :
}
/** Returns the value for the given key or the result of the defaultValue function is put into the map for the given value and returned */
inline fun <K,V> java.util.Map<K,V>.getOrElseUpdate(key: K, defaultValue: fun(): V) : V {
inline fun <K,V> java.util.Map<K,V>.getOrElseUpdate(key: K, defaultValue: ()-> V) : V {
val current = this.get(key)
if (current != null) {
return current
+3 -3
View File
@@ -1,6 +1,6 @@
namespace kotlin
package kotlin
namespace modules {
package modules {
import java.util.*
import jet.modules.*
@@ -8,7 +8,7 @@ import jet.modules.*
class ModuleSetBuilder(): IModuleSetBuilder {
val modules: ArrayList<IModuleBuilder?> = ArrayList<IModuleBuilder?>()
fun module(name: String, callback: fun ModuleBuilder.()) {
fun module(name: String, callback: ModuleBuilder.() -> Unit) {
val builder = ModuleBuilder(name)
builder.callback()
modules.add(builder)
+1 -1
View File
@@ -1,4 +1,4 @@
namespace std
package std
import java.io.StringReader
+3 -3
View File
@@ -1,9 +1,9 @@
namespace std.util
package std.util
/**
Executes current block and returns elapsed time in milliseconds
*/
fun measureTimeMillis(block: fun() : Unit) : Long {
fun measureTimeMillis(block: () -> Unit) : Long {
val start = System.currentTimeMillis()
block()
return System.currentTimeMillis() - start
@@ -12,7 +12,7 @@ fun measureTimeMillis(block: fun() : Unit) : Long {
/**
Executes current block and returns elapsed time in milliseconds
*/
fun measureTimeNano(block: fun() : Unit) : Long {
fun measureTimeNano(block: () -> Unit) : Long {
val start = System.nanoTime()
block()
return System.nanoTime() - start
+2 -2
View File
@@ -1,4 +1,4 @@
namespace std.concurrent
package std.concurrent
import java.lang.*
@@ -21,7 +21,7 @@ inline var Thread.contextClassLoader : ClassLoader?
get() = getContextClassLoader()
set(loader: ClassLoader?) { setContextClassLoader(loader) }
fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: fun():Unit) : Thread {
fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: ()->Unit) : Thread {
val thread = object: Thread() {
override fun run() {
block()