This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package a; | |
public abstract class A { | |
abstract void foo(); | |
public void callFooA() { | |
foo(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.coroutines.* | |
import kotlin.coroutines.intrinsics.* | |
/** | |
* Implementation for Delimited Continuations `shift`/`reset` primitives via Kotlin Coroutines. | |
* See [https://en.wikipedia.org/wiki/Delimited_continuation]. | |
* | |
* The following LISP code: | |
* | |
* ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Aspect interface for combinator | |
interface Aspect { | |
operator fun <R> invoke(block: () -> R): R | |
} | |
// Aspect combinator | |
operator fun Aspect.plus(other: Aspect) = object : Aspect { | |
override fun <R> invoke(block: () -> R): R = | |
this@plus { | |
other { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.coroutines.* | |
import kotlin.coroutines.intrinsics.* | |
// Solution for http://codeforces.com/problemset/problem/767/C | |
fun main() { | |
val n = readLine()!!.toInt() | |
val a = IntArray(n + 1) | |
val t = IntArray(n + 1) | |
for (i in 1..n) { | |
val (ai, ti) = readLine()!!.split(" ").map { it.toInt() } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person(val isClever: Boolean) | |
val p = Person(isClever = true) | |
// ERROR - missed "false" | |
val example1 = when (p.isClever) { | |
true -> "Yes, this person is clever" | |
} | |
// No error - all cases matched |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T : Any> CoroutineScope.deferredCache(block: suspend CoroutineScope.() -> T) : Deferred<T> = | |
async(start = CoroutineStart.LAZY) { | |
var result: T | |
while (true) { | |
try { | |
result = block() | |
break | |
} catch (e: Throwable) { | |
// failed -- retry | |
// todo: log exception somehow? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.delay | |
import kotlinx.coroutines.experimental.rx1.awaitFirst | |
import kotlinx.coroutines.experimental.rx1.rxObservable | |
import java.util.concurrent.TimeUnit | |
fun fetchFromNetwork() = rxObservable { | |
delay(1, TimeUnit.HOURS) | |
send("Result from network") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.Stream | |
abstract class NodeScaffold<THIS : NodeScaffold<THIS>> { | |
private val children: List<THIS>? = null | |
fun children(): Stream<THIS> { | |
return children!!.stream() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.* | |
fun main(args: Array<String>) { | |
class DomainSpecificException : RuntimeException() | |
val cf1 = CompletableFuture<Int>() | |
val cf2 = CompletableFuture<Int>() | |
val res = cf1.thenCompose { cf2 } | |
cf1.whenComplete { _, err -> println("cf1: Completed with error = $err") } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.* | |
import kotlinx.coroutines.experimental.channels.* | |
import kotlinx.coroutines.experimental.selects.* | |
import java.util.concurrent.* | |
// operator | |
fun <T> ReceiveChannel<T>.distinctInTimeWindow(time: Long, unit: TimeUnit): ReceiveChannel<T> = produce { | |
require(time > 0) | |
consume { | |
val source = this@distinctInTimeWindow |