GreatSyntacticShift: Codegen testdata fixed
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
namespace foo;
|
package foo;
|
||||||
|
|
||||||
fun main(args : Array<String>) {
|
fun main(args : Array<String>) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
fun box() : String {
|
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)
|
return f(arg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
fun box() : String {
|
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)
|
return f(arg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ fun box() : String {
|
|||||||
return if (sum(200, { val ff = {cl}; ff() }) == 239) "OK" else "FAIL"
|
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()
|
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"
|
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()
|
return arg + f()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
class Point(val x:Int, val y:Int) {
|
class Point(val x:Int, val y:Int) {
|
||||||
fun mul() : fun (scalar:Int):Point {
|
fun mul() : (scalar:Int)->Point {
|
||||||
return { (scalar:Int):Point => Point(x * scalar, y * scalar) }
|
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 {
|
fun box() : String {
|
||||||
val answer = m(5)
|
val answer = m(5)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
class Point(val x : Int, val y : Int)
|
class Point(val x : Int, val y : Int)
|
||||||
|
|
||||||
fun box() : String {
|
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)
|
Point(x * scalar, y * scalar)
|
||||||
})
|
})
|
||||||
|
|
||||||
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
|
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)
|
return arg.f(2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ fun box() : String {
|
|||||||
return invoker( {"OK"} )
|
return invoker( {"OK"} )
|
||||||
}
|
}
|
||||||
|
|
||||||
fun invoker(gen : fun () : String) : String {
|
fun invoker(gen : () -> String) : String {
|
||||||
return gen()
|
return gen()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ fun box() : String {
|
|||||||
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
|
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun int_invoker(gen : fun () : Int) : Int {
|
fun int_invoker(gen : () -> Int) : Int {
|
||||||
return gen()
|
return gen()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import java.util.concurrent.*
|
import java.util.concurrent.*
|
||||||
import java.util.concurrent.atomic.*
|
import java.util.concurrent.atomic.*
|
||||||
|
|
||||||
fun thread(block: fun():Unit ) {
|
fun thread(block: ()->Unit ) {
|
||||||
val thread = object: Thread() {
|
val thread = object: Thread() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
block()
|
block()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import java.util.*
|
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>()
|
val result = ArrayList<T>()
|
||||||
for(val t in this) {
|
for(val t in this) {
|
||||||
if (predicate(t)) result.add(t)
|
if (predicate(t)) result.add(t)
|
||||||
@@ -16,6 +16,6 @@ fun box(): String {
|
|||||||
list.add("Moscow")
|
list.add("Moscow")
|
||||||
list.add("Munich")
|
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"
|
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}
|
assert("$this must be $t") {this == t}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun assert(message : String, condition : fun() : Boolean) {
|
inline fun assert(message : String, condition : () -> Boolean) {
|
||||||
if (!condition())
|
if (!condition())
|
||||||
throw AssertionError(message)
|
throw AssertionError(message)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Request(val path: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Handler() {
|
class Handler() {
|
||||||
fun Int.times(op: fun(): Unit) {
|
fun Int.times(op: ()-> Unit) {
|
||||||
for(i in 0..this)
|
for(i in 0..this)
|
||||||
op()
|
op()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ fun StringBuilder.takeFirst(): Char {
|
|||||||
fun foo(expr: StringBuilder): Int {
|
fun foo(expr: StringBuilder): Int {
|
||||||
val c = expr.takeFirst()
|
val c = expr.takeFirst()
|
||||||
when(c) {
|
when(c) {
|
||||||
0.chr => throw Exception("zero")
|
0.chr -> throw Exception("zero")
|
||||||
else => throw Exception("nonzero" + c)
|
else -> throw Exception("nonzero" + c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ fun reformat(
|
|||||||
divideByCamelHumps : Boolean = true,
|
divideByCamelHumps : Boolean = true,
|
||||||
wordSeparator : String = " "
|
wordSeparator : String = " "
|
||||||
) =
|
) =
|
||||||
(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
|
#(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
|
||||||
|
|
||||||
trait A {
|
trait A {
|
||||||
fun bar2(arg: Int = 239) : Int
|
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 <T> T.toPrefixedString(prefix: String = "", suffix: String="") = prefix + (this as java.lang.Object).toString() + suffix
|
||||||
|
|
||||||
fun box() : String {
|
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(suffix="321", prefix="papa") != "papamama321") return "fail"
|
||||||
if("mama".toPrefixedString(prefix="papa") != "papamama") 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 }
|
return { "239" + this }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.foo2() : fun(i : Int) : Int {
|
fun Int.foo2() : (i : Int) -> Int {
|
||||||
return { x => x + this }
|
return { x -> x + this }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fooT1<T>(t : T) = { t.toString() }
|
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 {
|
fun box() : String {
|
||||||
if( (10.foo1())() != "23910") return "foo1 fail"
|
if( (10.foo1())() != "23910") return "foo1 fail"
|
||||||
if( (10.foo2())(1) != 11 ) return "foo2 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( {1}() != 1) return "test 4 failed";
|
||||||
if( {(x : Int) => x}(1) != 1) return "test 5 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.(x : Int) -> x + this}(1) != 2) return "test 6 failed";
|
||||||
if( 1.({Int.() => this})() != 1) return "test 7 failed";
|
if( 1.({Int.() -> this})() != 1) return "test 7 failed";
|
||||||
if( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
|
if( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
|
||||||
if( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
|
if( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
fun loop(var times : Int) {
|
fun loop(var times : Int) {
|
||||||
while(times > 0) {
|
while(times > 0) {
|
||||||
val u : fun(value : Int) : Unit = {
|
val u : (value : Int) -> Unit = {
|
||||||
System.out?.println(it)
|
System.out?.println(it)
|
||||||
}
|
}
|
||||||
u(times--)
|
u(times--)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class X<T> () {
|
class X<T> () {
|
||||||
fun getTypeChecker() = { (a : Any) => a is T }
|
fun getTypeChecker() = { (a : Any) -> a is T }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Foo {
|
package Foo {
|
||||||
fun bar() = 610
|
fun bar() = 610
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fun isZero(x: Int) = when(x) {
|
fun isZero(x: Int) = when(x) {
|
||||||
0 => true
|
0 -> true
|
||||||
else => false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
fun isZero(x: Int) = when(x) {
|
fun isZero(x: Int) = when(x) {
|
||||||
0 => true
|
0 -> true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
fun typeName(a: Any?) : String {
|
fun typeName(a: Any?) : String {
|
||||||
return when(a) {
|
return when(a) {
|
||||||
is java.util.ArrayList<*> => "array list"
|
is java.util.ArrayList<*> -> "array list"
|
||||||
else => "no idea"
|
else -> "no idea"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fun isString(x: Any) = when(x) {
|
fun isString(x: Any) = when(x) {
|
||||||
is String => "string"
|
is String -> "string"
|
||||||
else => "something"
|
else -> "something"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ fun isDigit(a: Int) : String {
|
|||||||
aa.add(239)
|
aa.add(239)
|
||||||
|
|
||||||
return when(a) {
|
return when(a) {
|
||||||
in aa => "array list"
|
in aa -> "array list"
|
||||||
in 0..9 => "digit"
|
in 0..9 -> "digit"
|
||||||
!in 0..100 => "not small"
|
!in 0..100 -> "not small"
|
||||||
else => "something"
|
else -> "something"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fun isDigit(a: Char) = when(a) {
|
fun isDigit(a: Char) = when(a) {
|
||||||
in '0'..'9' => "digit"
|
in '0'..'9' -> "digit"
|
||||||
else => "something"
|
else -> "something"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
fun main(args: Array<String>?) {
|
fun main(args: Array<String>?) {
|
||||||
val y: Unit = () //do not compile
|
val y: Unit = #() //do not compile
|
||||||
A<Unit>() //do not compile
|
A<Unit>() //do not compile
|
||||||
C<Unit>(()) //do not compile
|
C<Unit>(#()) //do not compile
|
||||||
//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(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>()
|
class A<T>()
|
||||||
|
|
||||||
@@ -17,13 +17,13 @@ fun <T> fff(x: T) : T { return x }
|
|||||||
|
|
||||||
fun <T> id(value: T): T = value
|
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) {
|
for (el in array) {
|
||||||
action(el) //exception through compilation (see below)
|
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) {
|
for (el in array) {
|
||||||
action(el)
|
action(el)
|
||||||
}
|
}
|
||||||
@@ -34,8 +34,8 @@ fun box() : String {
|
|||||||
a[0] = 0
|
a[0] = 0
|
||||||
a[1] = 1
|
a[1] = 1
|
||||||
a[2] = 2
|
a[2] = 2
|
||||||
foreach(a, { (el : Int) : Unit => System.out?.println(el) })
|
foreach(a, { (el : Int) : Unit -> System.out?.println(el) })
|
||||||
almostFilter(a, { (el : Int) : Int => el })
|
almostFilter(a, { (el : Int) : Int -> el })
|
||||||
main(null)
|
main(null)
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace x
|
package x
|
||||||
|
|
||||||
class Outer() {
|
class Outer() {
|
||||||
class object {
|
class object {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace test
|
package test
|
||||||
|
|
||||||
class List<T>(len: Int) {
|
class List<T>(len: Int) {
|
||||||
val a : Array<T?> = Array<T?>(len)
|
val a : Array<T?> = Array<T?>(len)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
fun launch(f : fun() : Unit) {
|
fun launch(f : () -> Unit) {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
val list = ArrayList<Int>()
|
val list = ArrayList<Int>()
|
||||||
val foo : fun() : Unit = {
|
val foo : () -> Unit = {
|
||||||
list.add(2) //first exception
|
list.add(2) //first exception
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ fun t1() : Boolean {
|
|||||||
x = x + "45" + y
|
x = x + "45" + y
|
||||||
x = x.substring(3)
|
x = x.substring(3)
|
||||||
x += "aaa"
|
x += "aaa"
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ fun t2() : Boolean {
|
|||||||
x = x + 5 + y
|
x = x + 5 + y
|
||||||
x += 5
|
x += 5
|
||||||
x++
|
x++
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
x -= 55
|
x -= 55
|
||||||
@@ -55,7 +55,7 @@ fun t3() : Boolean {
|
|||||||
var x = true
|
var x = true
|
||||||
val foo = {
|
val foo = {
|
||||||
x = false
|
x = false
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
return !x
|
return !x
|
||||||
@@ -67,7 +67,7 @@ fun t4() : Boolean {
|
|||||||
val foo = {
|
val foo = {
|
||||||
x = x + 200.flt + y
|
x = x + 200.flt + y
|
||||||
x += 18
|
x += 18
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
System.out?.println(x)
|
System.out?.println(x)
|
||||||
@@ -80,7 +80,7 @@ fun t5() : Boolean {
|
|||||||
val foo = {
|
val foo = {
|
||||||
x = x + 200.dbl + y
|
x = x + 200.dbl + y
|
||||||
x -= 22
|
x -= 22
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
System.out?.println(x)
|
System.out?.println(x)
|
||||||
@@ -94,7 +94,7 @@ fun t6() : Boolean {
|
|||||||
x = (x + 20.byt + y).byt
|
x = (x + 20.byt + y).byt
|
||||||
x += 2
|
x += 2
|
||||||
x--
|
x--
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
System.out?.println(x)
|
System.out?.println(x)
|
||||||
@@ -105,7 +105,7 @@ fun t7() : Boolean {
|
|||||||
var x : Char = 'a'
|
var x : Char = 'a'
|
||||||
val foo = {
|
val foo = {
|
||||||
x = 'b'
|
x = 'b'
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
System.out?.println(x)
|
System.out?.println(x)
|
||||||
@@ -117,10 +117,10 @@ fun t8() : Boolean {
|
|||||||
val foo = {
|
val foo = {
|
||||||
val bar = {
|
val bar = {
|
||||||
x = 30.sht
|
x = 30.sht
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
bar()
|
bar()
|
||||||
()
|
#()
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
return x == 30.sht
|
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 {
|
fun box () : String {
|
||||||
return if(20.with {
|
return if(20.with {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace mult_constructors_3_bug
|
package mult_constructors_3_bug
|
||||||
|
|
||||||
public open class Identifier() {
|
public open class Identifier() {
|
||||||
private var myNullable : Boolean = true
|
private var myNullable : Boolean = true
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace one_extends_base
|
package one_extends_base
|
||||||
|
|
||||||
open class Base<T>(name : T?) {
|
open class Base<T>(name : T?) {
|
||||||
var myName : T?
|
var myName : T?
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace mask
|
package mask
|
||||||
|
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -52,7 +52,7 @@ class Luhny() {
|
|||||||
fun check() {
|
fun check() {
|
||||||
if (digits.size() < 14) return
|
if (digits.size() < 14) return
|
||||||
print("check")
|
print("check")
|
||||||
val sum = digits.sum { i, d =>
|
val sum = digits.sum { i, d ->
|
||||||
// println("$i -> $d")
|
// println("$i -> $d")
|
||||||
if (i % 2 == digits.size()) {
|
if (i % 2 == digits.size()) {
|
||||||
val f = d * 2 / 10
|
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)
|
f(this)
|
||||||
return 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
|
var sum = 0
|
||||||
for (i in 1..size()) {
|
for (i in 1..size()) {
|
||||||
val j = size() - i
|
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 Char.isDigit() = Character.isDigit(this)
|
||||||
|
|
||||||
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
fun Reader.forEachChar(body : (Char) -> Unit) {
|
||||||
do {
|
do {
|
||||||
var i = read();
|
var i = read();
|
||||||
if (i == -1) break
|
if (i == -1) break
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace mask
|
package mask
|
||||||
|
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -46,7 +46,7 @@ class Luhny() {
|
|||||||
private fun check() {
|
private fun check() {
|
||||||
val size = digits.size()
|
val size = digits.size()
|
||||||
if (size < 14) return
|
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
|
if (i % 2 == size % 2) double(d) else d
|
||||||
}
|
}
|
||||||
// var sum = 0
|
// var sum = 0
|
||||||
@@ -89,7 +89,7 @@ class Luhny() {
|
|||||||
|
|
||||||
fun Char.isDigit() = Character.isDigit(this)
|
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 sum = 0
|
||||||
var i = 0
|
var i = 0
|
||||||
for (d in this) {
|
for (d in this) {
|
||||||
@@ -99,7 +99,7 @@ fun java.lang.Iterable<Int>.sum(f : fun(index : Int, value : Int) : Int) : Int {
|
|||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
fun Reader.forEachChar(body : (Char) -> Unit) {
|
||||||
do {
|
do {
|
||||||
var i = read();
|
var i = read();
|
||||||
if (i == -1) break
|
if (i == -1) break
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace mask
|
package mask
|
||||||
|
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -50,7 +50,7 @@ class Luhny() {
|
|||||||
|
|
||||||
fun check() {
|
fun check() {
|
||||||
if (digits.size() < 14) return
|
if (digits.size() < 14) return
|
||||||
val sum = digits.sum { i, d =>
|
val sum = digits.sum { i, d ->
|
||||||
if (i % 2 != 0)
|
if (i % 2 != 0)
|
||||||
d * 2 / 10 + d * 2 % 10
|
d * 2 / 10 + d * 2 % 10
|
||||||
else d
|
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 sum = 0
|
||||||
var i = 0
|
var i = 0
|
||||||
for (d in backwards()) {
|
for (d in backwards()) {
|
||||||
@@ -136,7 +136,7 @@ fun Char.isDigit() = Character.isDigit(this)
|
|||||||
// fun clear() {}
|
// fun clear() {}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
fun Reader.forEachChar(body : (Char) -> Unit) {
|
||||||
do {
|
do {
|
||||||
var i = read();
|
var i = read();
|
||||||
if (i == -1) break
|
if (i == -1) break
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace while_bug_1
|
package while_bug_1
|
||||||
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace whats.the.difference
|
package whats.the.difference
|
||||||
|
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace array_test
|
package array_test
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
var array : IntArray? = IntArray(10)
|
var array : IntArray? = IntArray(10)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace name
|
package name
|
||||||
|
|
||||||
class Test() {
|
class Test() {
|
||||||
var i = 5
|
var i = 5
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace demo
|
package demo
|
||||||
|
|
||||||
public open class Identifier<T>(myName : T?, myHasDollar : Boolean) {
|
public open class Identifier<T>(myName : T?, myHasDollar : Boolean) {
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
fun escapeChar(c : Char) : String? = when (c) {
|
fun escapeChar(c : Char) : String? = when (c) {
|
||||||
'\\' => "\\\\"
|
'\\' -> "\\\\"
|
||||||
'\n' => "\\n"
|
'\n' -> "\\n"
|
||||||
'"' => "\\\""
|
'"' -> "\\\""
|
||||||
else => String.valueOf(c)
|
else -> String.valueOf(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.escape(i : Int = 0, result : String = "") : String =
|
fun String.escape(i : Int = 0, result : String = "") : String =
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace org2
|
package org2
|
||||||
|
|
||||||
enum class Test {
|
enum class Test {
|
||||||
A
|
A
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class List<T>(val head: T, val tail: List<T>? = null)
|
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 {
|
fun box() : String {
|
||||||
val a: Int = List<Int>(1).mapHead{it * 2}.head
|
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())
|
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())
|
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?.plus() : Int = this.sure().plus()
|
||||||
fun Int?.dec() : Int = this.sure().dec()
|
fun Int?.dec() : Int = this.sure().dec()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace demo_long
|
package demo_long
|
||||||
|
|
||||||
fun Long?.inv() : Long = this.sure().inv()
|
fun Long?.inv() : Long = this.sure().inv()
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
namespace w_range
|
package w_range
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
var i = 0
|
var i = 0
|
||||||
when (i) {
|
when (i) {
|
||||||
1 => i--
|
1 -> i--
|
||||||
else => { i = 2 }
|
else -> { i = 2 }
|
||||||
}
|
}
|
||||||
System.out?.println(i)
|
System.out?.println(i)
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
namespace demo2
|
package demo2
|
||||||
|
|
||||||
fun print(o : Any?) {}
|
fun print(o : Any?) {}
|
||||||
|
|
||||||
fun test(i : Int) {
|
fun test(i : Int) {
|
||||||
var monthString : String? = "<empty>"
|
var monthString : String? = "<empty>"
|
||||||
when (i) {
|
when (i) {
|
||||||
1 => {
|
1 -> {
|
||||||
print(1)
|
print(1)
|
||||||
print(2)
|
print(2)
|
||||||
print(3)
|
print(3)
|
||||||
print(4)
|
print(4)
|
||||||
print(5)
|
print(5)
|
||||||
}
|
}
|
||||||
else => {
|
else -> {
|
||||||
monthString = "Invalid month"
|
monthString = "Invalid month"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
namespace demo2
|
package demo2
|
||||||
|
|
||||||
fun print(o : Any?) {}
|
fun print(o : Any?) {}
|
||||||
|
|
||||||
fun test(i : Int) {
|
fun test(i : Int) {
|
||||||
var monthString : String? = "<empty>"
|
var monthString : String? = "<empty>"
|
||||||
when (i) {
|
when (i) {
|
||||||
1 => {
|
1 -> {
|
||||||
print(1)
|
print(1)
|
||||||
print(2)
|
print(2)
|
||||||
print(3)
|
print(3)
|
||||||
print(4)
|
print(4)
|
||||||
print(5)
|
print(5)
|
||||||
}
|
}
|
||||||
else => {
|
else -> {
|
||||||
monthString = "Invalid month"
|
monthString = "Invalid month"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class A() {
|
class A() {
|
||||||
var x : Int = 0
|
var x : Int = 0
|
||||||
|
|
||||||
var z = { () =>
|
var z = { () ->
|
||||||
x++
|
x++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace foo
|
package foo
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace demo
|
package demo
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
var res : Boolean = true
|
var res : Boolean = true
|
||||||
|
|||||||
@@ -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)
|
private val array = Array<T>(length, init)
|
||||||
|
|
||||||
override fun get(index : Int) : T = array[index]
|
override fun get(index : Int) : T = array[index]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
|
|||||||
|
|
||||||
fun test() : Int {
|
fun test() : Int {
|
||||||
foo(1)
|
foo(1)
|
||||||
val a : fun() : Unit = {
|
val a : () -> Unit = {
|
||||||
foo(1)
|
foo(1)
|
||||||
}
|
}
|
||||||
return 1 - "1"
|
return 1 - "1"
|
||||||
|
|||||||
@@ -485,7 +485,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testTupleLiteral() throws Exception {
|
public void testTupleLiteral() throws Exception {
|
||||||
loadText("fun foo() = (1, \"foo\")");
|
loadText("fun foo() = #(1, \"foo\")");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction("foo");
|
final Method main = generateFunction("foo");
|
||||||
Tuple2 tuple2 = (Tuple2) main.invoke(null);
|
Tuple2 tuple2 = (Tuple2) main.invoke(null);
|
||||||
@@ -494,7 +494,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testParametrizedTupleLiteral() throws Exception {
|
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());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
Tuple4 tuple4 = (Tuple4) main.invoke(null, "aaa", TypeInfo.STRING_TYPE_INFO, TypeInfo.INT_TYPE_INFO, Arrays.asList(10));
|
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 {
|
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();
|
Method foo = generateFunction();
|
||||||
assertEquals("something", foo.invoke(null, ""));
|
assertEquals("something", foo.invoke(null, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoReturnType() throws Exception {
|
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();
|
Method foo = generateFunction();
|
||||||
assertEquals("x", foo.invoke(null, ""));
|
assertEquals("x", foo.invoke(null, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTuplePattern() throws Exception {
|
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();
|
Method foo = generateFunction();
|
||||||
final Object result;
|
final Object result;
|
||||||
try {
|
try {
|
||||||
@@ -118,14 +118,14 @@ public class PatternMatchingTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testNames() throws Exception {
|
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();
|
Method foo = generateFunction();
|
||||||
assertEquals("JetBrains", foo.invoke(null, new Tuple2<String, String>(null, "JetBrains", "s.r.o.")));
|
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)));
|
assertEquals("something", foo.invoke(null, new Tuple2<Integer, Integer>(null, 1, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleConditions() throws Exception {
|
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();
|
Method foo = generateFunction();
|
||||||
assertEquals("bit", foo.invoke(null, 0));
|
assertEquals("bit", foo.invoke(null, 0));
|
||||||
assertEquals("bit", foo.invoke(null, 1));
|
assertEquals("bit", foo.invoke(null, 1));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace std
|
package std
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace std
|
package std
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.lang.Iterable
|
import java.lang.Iterable
|
||||||
@@ -6,7 +6,7 @@ import java.lang.Iterable
|
|||||||
/*
|
/*
|
||||||
Filters given iterator
|
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
|
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)
|
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 state = 0
|
||||||
var nextElement: T? = null
|
var nextElement: T? = null
|
||||||
|
|
||||||
override fun hasNext(): Boolean =
|
override fun hasNext(): Boolean =
|
||||||
when(state) {
|
when(state) {
|
||||||
1 => true // checked and next present
|
1 -> true // checked and next present
|
||||||
2 => false // checked and next not present
|
2 -> false // checked and next not present
|
||||||
else => {
|
else -> {
|
||||||
while(original.hasNext()) {
|
while(original.hasNext()) {
|
||||||
val candidate = original.next()
|
val candidate = original.next()
|
||||||
if((filter)(candidate)) {
|
if((filter)(candidate)) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace std.util
|
package std.util
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.Iterator
|
import java.util.Iterator
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace std
|
package std
|
||||||
|
|
||||||
namespace io {
|
package io {
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.nio.charset.*
|
import java.nio.charset.*
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -1,4 +1,4 @@
|
|||||||
namespace std.util
|
package std.util
|
||||||
|
|
||||||
import java.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))
|
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 */
|
/** 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) {
|
for (elem in this) {
|
||||||
if (predicate(elem)) {
|
if (predicate(elem)) {
|
||||||
return true
|
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 */
|
/** 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) {
|
for (elem in this) {
|
||||||
if (!predicate(elem)) {
|
if (!predicate(elem)) {
|
||||||
return false
|
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 */
|
/** 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) {
|
for (elem in this) {
|
||||||
if (predicate(elem))
|
if (predicate(elem))
|
||||||
return 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 */
|
/** 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) {
|
for (elem in this) {
|
||||||
if (predicate(elem))
|
if (predicate(elem))
|
||||||
result.add(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
|
* Returns the result of transforming each item in the collection to a one or more values which
|
||||||
* are concatenated together into a single collection
|
* 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) {
|
for (elem in this) {
|
||||||
val coll = transform(elem)
|
val coll = transform(elem)
|
||||||
if (coll != null) {
|
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 */
|
/** 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)
|
for (elem in this)
|
||||||
operation(elem)
|
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 */
|
/** 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)
|
for (item in this)
|
||||||
result.add(transform(item))
|
result.add(transform(item))
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new collection containing the results of applying the given function to each element in this collection */
|
/** 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)
|
for (item in this)
|
||||||
result.add(transform(item))
|
result.add(transform(item))
|
||||||
return result
|
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 */
|
/** 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)
|
val current = this.get(key)
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
return current
|
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 */
|
/** 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)
|
val current = this.get(key)
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
return current
|
return current
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace kotlin
|
package kotlin
|
||||||
|
|
||||||
namespace modules {
|
package modules {
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import jet.modules.*
|
import jet.modules.*
|
||||||
@@ -8,7 +8,7 @@ import jet.modules.*
|
|||||||
class ModuleSetBuilder(): IModuleSetBuilder {
|
class ModuleSetBuilder(): IModuleSetBuilder {
|
||||||
val modules: ArrayList<IModuleBuilder?> = ArrayList<IModuleBuilder?>()
|
val modules: ArrayList<IModuleBuilder?> = ArrayList<IModuleBuilder?>()
|
||||||
|
|
||||||
fun module(name: String, callback: fun ModuleBuilder.()) {
|
fun module(name: String, callback: ModuleBuilder.() -> Unit) {
|
||||||
val builder = ModuleBuilder(name)
|
val builder = ModuleBuilder(name)
|
||||||
builder.callback()
|
builder.callback()
|
||||||
modules.add(builder)
|
modules.add(builder)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace std
|
package std
|
||||||
|
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
namespace std.util
|
package std.util
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Executes current block and returns elapsed time in milliseconds
|
Executes current block and returns elapsed time in milliseconds
|
||||||
*/
|
*/
|
||||||
fun measureTimeMillis(block: fun() : Unit) : Long {
|
fun measureTimeMillis(block: () -> Unit) : Long {
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
block()
|
block()
|
||||||
return System.currentTimeMillis() - start
|
return System.currentTimeMillis() - start
|
||||||
@@ -12,7 +12,7 @@ fun measureTimeMillis(block: fun() : Unit) : Long {
|
|||||||
/**
|
/**
|
||||||
Executes current block and returns elapsed time in milliseconds
|
Executes current block and returns elapsed time in milliseconds
|
||||||
*/
|
*/
|
||||||
fun measureTimeNano(block: fun() : Unit) : Long {
|
fun measureTimeNano(block: () -> Unit) : Long {
|
||||||
val start = System.nanoTime()
|
val start = System.nanoTime()
|
||||||
block()
|
block()
|
||||||
return System.nanoTime() - start
|
return System.nanoTime() - start
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace std.concurrent
|
package std.concurrent
|
||||||
|
|
||||||
import java.lang.*
|
import java.lang.*
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ inline var Thread.contextClassLoader : ClassLoader?
|
|||||||
get() = getContextClassLoader()
|
get() = getContextClassLoader()
|
||||||
set(loader: ClassLoader?) { setContextClassLoader(loader) }
|
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() {
|
val thread = object: Thread() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
block()
|
block()
|
||||||
|
|||||||
Reference in New Issue
Block a user