Update notebooks
This commit is contained in:
parent
5dfd67b563
commit
85b1931673
@ -138,7 +138,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "println(\"This is a string with \\$\")",
|
||||
"source": "println(\"This is a string with \\$a\")",
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"node_id": "hm9iYlWj1B2S0469GtxDrf",
|
||||
@ -157,13 +157,16 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"println(\"\"\"\n",
|
||||
"println(\n",
|
||||
" \"\"\"\n",
|
||||
" \\\\\\\n",
|
||||
" This is a \n",
|
||||
" multi\n",
|
||||
" line\n",
|
||||
" raw\n",
|
||||
" string\n",
|
||||
"\"\"\".trimIndent())"
|
||||
"\"\"\".trimIndent()\n",
|
||||
")"
|
||||
],
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
@ -182,9 +185,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"println(\"\"\"This is a raw string number ${number+1} with \\ and ${'$'} \"\"\")"
|
||||
],
|
||||
"source": "println(\"\"\"This is a raw string number ${number + 1} with \\ and ${'$'} \"\"\")",
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"node_id": "KDL3D9lOVn6vX3iTAY50gb",
|
||||
@ -295,6 +296,20 @@
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"var _a = 2\n",
|
||||
"val a: Int get() = _a\n",
|
||||
"\n",
|
||||
"println(a)\n",
|
||||
"_a = 3\n",
|
||||
"println(a)"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
@ -384,6 +399,7 @@
|
||||
"fun doSomethingSpecial() {\n",
|
||||
" val base = \"base\"\n",
|
||||
" val special = \"special\"\n",
|
||||
"\n",
|
||||
" /**\n",
|
||||
" * This one is inside another function\n",
|
||||
" */\n",
|
||||
@ -462,7 +478,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"fun returnUnit(): Unit {\n",
|
||||
" // no return statement `Unit` is returned implicitly\n",
|
||||
" val b = Unit\n",
|
||||
@ -520,9 +535,10 @@
|
||||
"}\n",
|
||||
"\n",
|
||||
"doSomethingWithDefault()\n",
|
||||
"doSomethingWithDefault(4)\n",
|
||||
"doSomethingWithDefault(2, \"aaa\")\n",
|
||||
"doSomethingWithDefault(b = \"fff\", a = 8)\n",
|
||||
"doSomethingWithDefault(4, b = \"fff\")\n",
|
||||
"doSomethingWithDefault(6, b = \"fff\")\n",
|
||||
"doSomethingWithDefault(a = 2, \"fff\")// don't do that"
|
||||
],
|
||||
"metadata": {
|
||||
@ -591,7 +607,7 @@
|
||||
"\n",
|
||||
"//@JvmOverloads\n",
|
||||
"@JvmName(\"functionWithDefaultParameters\")\n",
|
||||
"fun functionWithParameters(a: Int = 2){\n",
|
||||
"fun functionWithParameters(a: Int = 2) { // don't do that\n",
|
||||
" println(\"with default\")\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
@ -717,13 +733,16 @@
|
||||
"source": [
|
||||
"//Interfaces and objects\n",
|
||||
"\n",
|
||||
"interface AnInterface {\n",
|
||||
"fun interface AnInterface {\n",
|
||||
" val a: Int\n",
|
||||
" get() = 4\n",
|
||||
"\n",
|
||||
" // set(value){\n",
|
||||
" // println(value)\n",
|
||||
" // }\n",
|
||||
" fun doSomething() //= println(\"From interface\")\n",
|
||||
"\n",
|
||||
" fun doSomething2() = Unit\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"abstract class AnAbstractClass(override val a: Int) : AnInterface {\n",
|
||||
@ -761,6 +780,11 @@
|
||||
" */\n",
|
||||
"val anonymous = object : AnInterface {\n",
|
||||
" override fun doSomething(): Unit = TODO(\"Not yet implemented\")\n",
|
||||
" override fun doSomething2(): Unit = TODO(\"Not yet implemented\")\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"val anonymous2 = AnInterface {\n",
|
||||
" println(\"Do something\")\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/**\n",
|
||||
@ -994,7 +1018,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"val res: Result<Int> = runCatching<Int> {\n",
|
||||
" //error(\"Error happened\")\n",
|
||||
" 4\n",
|
||||
@ -1098,6 +1121,19 @@
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"fun loop(block: () -> Unit): Nothing {\n",
|
||||
" while (true) {\n",
|
||||
" block()\n",
|
||||
" }\n",
|
||||
"}"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
@ -1116,13 +1152,16 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"class SimpleClass(val a: Int, val b: Double, c: Double) {\n",
|
||||
" override fun toString() = \"SimpleClass(a=$a, b=$b)\"\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"data class DataClass(val a: Int, var b: Double /*, d: Double */) {\n",
|
||||
" init {\n",
|
||||
" require(b >= 0) { \"B should be positive\" }\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" val c get() = b + 1\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
@ -1237,6 +1276,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"import java.io.File\n",
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * Safe call and elvis operator\n",
|
||||
@ -1311,7 +1351,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * Dart-like (?=) nullable assignment\n",
|
||||
" */\n",
|
||||
@ -1405,7 +1444,7 @@
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": "",
|
||||
"source": "0.0..8.0 intersect 2.9..6.1",
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
@ -1467,7 +1506,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * Extension property (must be virtual)\n",
|
||||
" */\n",
|
||||
@ -1499,7 +1537,14 @@
|
||||
" }\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"val map = mutableMapOf(\"a\" to \"a\", \"b\" to \"b\")\n",
|
||||
"val map = mutableMapOf(\n",
|
||||
" \"a\" to \"a\",\n",
|
||||
" \"b\" to \"b\"\n",
|
||||
")\n",
|
||||
"val map2 = mutableMapOf(\n",
|
||||
" Pair(\"a\", \"a\"),\n",
|
||||
" Pair(\"b\", \"b\")\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"map.a = \"6\"\n",
|
||||
"\n",
|
||||
@ -1519,7 +1564,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * Extension variable (also must be virtual)\n",
|
||||
" */\n",
|
||||
@ -1617,7 +1661,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"//using `run`\n",
|
||||
"getAClass()?.takeIf { it.a.isNotEmpty() }?.run {\n",
|
||||
" // the same as above\n",
|
||||
@ -1650,7 +1693,15 @@
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"//Don't do that\n",
|
||||
"fun scopeAbuse(str: String?) = str.takeIf { it?.isNotEmpty() == true }?.let { it.substring(0..4) }?.let { it.matches(\".*\".toRegex())}"
|
||||
"fun scopeAbuse(str: String?) =\n",
|
||||
" str.takeIf { it?.isNotEmpty() == true }?.let { it.substring(0..4) }?.let { it.matches(\".*\".toRegex()) }\n",
|
||||
"\n",
|
||||
"fun withoutAbuse(str: String?): Boolean? = if (str?.isNotEmpty() == true) {\n",
|
||||
" val substring = str.substring(0..4)\n",
|
||||
" substring.matches(\".*\".toRegex())\n",
|
||||
"} else {\n",
|
||||
" null\n",
|
||||
"}"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
@ -1683,6 +1734,10 @@
|
||||
" */\n",
|
||||
"fun getAndIncrement() = i.also { i += 1 } //don't do that\n",
|
||||
"\n",
|
||||
"fun incrementAndPring(arg: Int) = (arg + 1).also{\n",
|
||||
" println(it)\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"println(getAndIncrement())\n",
|
||||
"println(i)"
|
||||
],
|
||||
@ -1700,7 +1755,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"class Rectangle {\n",
|
||||
" var length: Number = 0\n",
|
||||
" var breadth: Number = 0\n",
|
||||
@ -1740,6 +1794,13 @@
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": "",
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
@ -1790,7 +1851,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * This one creates a mutable list\n",
|
||||
" */\n",
|
||||
@ -1815,7 +1875,6 @@
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"//don't do that ever\n",
|
||||
"fun doBadThingWithList(list: List<String>): List<String> = (list as MutableList<String>).apply { add(\"something\") }\n",
|
||||
"\n",
|
||||
@ -1895,7 +1954,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * This one creates a mutable ArrayList.\n",
|
||||
" */\n",
|
||||
@ -1923,7 +1981,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"//Bonus\n",
|
||||
"\n",
|
||||
"val lambdaList = List(3) { it.toString() }\n",
|
||||
@ -1934,6 +1991,7 @@
|
||||
" add(8)\n",
|
||||
" remove(8)\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"builderList"
|
||||
],
|
||||
"metadata": {
|
||||
@ -2055,7 +2113,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"//val entry: MutableMap.MutableEntry<String, String> = map.iterator().next()\n",
|
||||
"\n",
|
||||
"//map.entries.first().component2()\n",
|
||||
@ -2083,7 +2140,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "map.forEach { (k, v) -> println(\"$k -> $v\")}",
|
||||
"source": [
|
||||
"map.forEach { (k, v) -> println(\"$k -> $v\") }\n",
|
||||
"\n",
|
||||
"// java version\n",
|
||||
"map.forEach { k, v -> println(\"$k -> $v\") }"
|
||||
],
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"node_id": "s1Q65aNWb9YNBZOgxmjotW",
|
||||
@ -2098,7 +2160,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"val (a, b) = Pair(1, 2)\n",
|
||||
"\n",
|
||||
"val coord = doubleArrayOf(0.0, 1.0, 2.0)\n",
|
||||
@ -2158,7 +2219,6 @@
|
||||
"}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"val obj = AClassWithList()\n",
|
||||
"\n",
|
||||
"// obj.b = 10.0 //error\n",
|
||||
@ -2178,9 +2238,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Wrap mutable logic"
|
||||
],
|
||||
"source": "## Wrap mutable logic / Kotlin builder pattern",
|
||||
"attachments": {},
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
@ -2226,7 +2284,7 @@
|
||||
" fun build() = ImmutableObject(a, b, c)\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"fun ImmutableObject(a: String, block: ImmutableObjectBuilder.() -> Unit): ImmutableObject =\n",
|
||||
"/*inline*/ fun ImmutableObject(a: String, block: ImmutableObjectBuilder.() -> Unit): ImmutableObject =\n",
|
||||
" ImmutableObjectBuilder(a).apply(block).build()\n",
|
||||
"\n",
|
||||
"ImmutableObject(\"aValue\") {\n",
|
||||
@ -2259,7 +2317,6 @@
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"val emailsList = emptyList<String>()\n",
|
||||
"\n",
|
||||
"// When used directly infix in operator checks if the element is contained in a collection\n",
|
||||
@ -2310,7 +2367,6 @@
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"// Another (different) use of `in` is iteration over range or collection using\n",
|
||||
"// using `operator fun iterator`\n",
|
||||
"\n",
|
||||
@ -2385,6 +2441,7 @@
|
||||
" //.onEach { println(it) }\n",
|
||||
" //.sumOf { it } //use one of reduce operations\n",
|
||||
" .reduce { acc: Int, i: Int -> acc + i }\n",
|
||||
" //.fold(0.0) { acc: Double, i: Int -> acc + i }\n",
|
||||
"\n",
|
||||
"result"
|
||||
],
|
||||
@ -2534,7 +2591,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"open class Bad {\n",
|
||||
" val value: Int = requestValue()\n",
|
||||
"\n",
|
||||
@ -2586,8 +2642,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"//Factory functions are preferred to the initialization logic\n",
|
||||
"\n",
|
||||
"data class Good internal constructor(val value: Int) {\n",
|
||||
@ -2599,11 +2653,10 @@
|
||||
" companion object\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"fun requestValue(): Int = TODO()\n",
|
||||
"private fun requestValue(): Int = TODO()\n",
|
||||
"\n",
|
||||
"// This is the factory-function\n",
|
||||
"fun Good() = Good(requestValue())\n",
|
||||
"\n",
|
||||
"fun Good(): Good = Good(requestValue())\n",
|
||||
"\n",
|
||||
"// additional constructor-like builders could be added to the companion\n",
|
||||
"\n",
|
||||
@ -2649,16 +2702,18 @@
|
||||
" 22\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" val getterValue: Int get(){\n",
|
||||
" val getterValue: Int\n",
|
||||
" get() {\n",
|
||||
" println(\"got\")\n",
|
||||
" return 33\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"val lazyClass = ClassWithALazyProperty()\n",
|
||||
"lazyClass.lazyValue\n",
|
||||
"lazyClass.lazyValue\n",
|
||||
"lazyClass.getterValue\n",
|
||||
"lazyClass.getterValue"
|
||||
"println(lazyClass.lazyValue)\n",
|
||||
"println(lazyClass.lazyValue)\n",
|
||||
"println(lazyClass.getterValue)\n",
|
||||
"println(lazyClass.getterValue)"
|
||||
],
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
@ -2674,7 +2729,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"//Using other delegates\n",
|
||||
"val map = mutableMapOf(\"a\" to 1, \"b\" to 2)\n",
|
||||
"\n",
|
||||
@ -2713,7 +2767,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * Definition of inline function\n",
|
||||
" */\n",
|
||||
@ -2749,7 +2802,6 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\n",
|
||||
"/**\n",
|
||||
" * Using inline function for type reification during the compile time\n",
|
||||
" */\n",
|
||||
|
@ -2,7 +2,6 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -11,10 +10,11 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%use coroutines"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@ -40,7 +40,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -49,16 +48,16 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"repeat(10){\n",
|
||||
" println(\"Line number $it\")\n",
|
||||
"}"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -67,12 +66,13 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import java.util.stream.*\n",
|
||||
"\n",
|
||||
"IntStream.range(0, 100).sum()"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -91,7 +91,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -100,64 +99,18 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"null\n",
|
||||
"java.util.ConcurrentModificationException\n",
|
||||
"\tat java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1095)\n",
|
||||
"\tat java.base/java.util.ArrayList$Itr.next(ArrayList.java:1049)\n",
|
||||
"\tat Line_0_jupyter.<init>(Line_0.jupyter.kts:6)\n",
|
||||
"\tat java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)\n",
|
||||
"\tat java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)\n",
|
||||
"\tat java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)\n",
|
||||
"\tat kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:122)\n",
|
||||
"\tat kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke$suspendImpl(BasicJvmScriptEvaluator.kt:48)\n",
|
||||
"\tat kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke(BasicJvmScriptEvaluator.kt)\n",
|
||||
"\tat kotlin.script.experimental.jvm.BasicJvmReplEvaluator.eval(BasicJvmReplEvaluator.kt:49)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.InternalEvaluatorImpl$eval$resultWithDiagnostics$1.invokeSuspend(InternalEvaluatorImpl.kt:127)\n",
|
||||
"\tat kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)\n",
|
||||
"\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)\n",
|
||||
"\tat kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)\n",
|
||||
"\tat kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95)\n",
|
||||
"\tat kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69)\n",
|
||||
"\tat kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)\n",
|
||||
"\tat kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48)\n",
|
||||
"\tat kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.InternalEvaluatorImpl.eval(InternalEvaluatorImpl.kt:127)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl$execute$1$result$1.invoke(CellExecutorImpl.kt:79)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl$execute$1$result$1.invoke(CellExecutorImpl.kt:77)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.withHost(ReplForJupyterImpl.kt:758)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl.execute(CellExecutorImpl.kt:77)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.execution.CellExecutor$DefaultImpls.execute$default(CellExecutor.kt:12)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.evaluateUserCode(ReplForJupyterImpl.kt:581)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.access$evaluateUserCode(ReplForJupyterImpl.kt:136)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl$evalEx$1.invoke(ReplForJupyterImpl.kt:439)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl$evalEx$1.invoke(ReplForJupyterImpl.kt:436)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.withEvalContext(ReplForJupyterImpl.kt:417)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.evalEx(ReplForJupyterImpl.kt:436)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.messaging.IdeCompatibleMessageRequestProcessor$processExecuteRequest$1$response$1$1.invoke(IdeCompatibleMessageRequestProcessor.kt:140)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.messaging.IdeCompatibleMessageRequestProcessor$processExecuteRequest$1$response$1$1.invoke(IdeCompatibleMessageRequestProcessor.kt:139)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.execution.JupyterExecutorImpl$Task.execute(JupyterExecutorImpl.kt:42)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.execution.JupyterExecutorImpl$executorThread$1.invoke(JupyterExecutorImpl.kt:82)\n",
|
||||
"\tat org.jetbrains.kotlinx.jupyter.execution.JupyterExecutorImpl$executorThread$1.invoke(JupyterExecutorImpl.kt:80)\n",
|
||||
"\tat kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"val list = (0..100).toMutableList()\n",
|
||||
"\n",
|
||||
"list.forEach {\n",
|
||||
" if(it % 2 == 0) list.remove(it)\n",
|
||||
"}"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -166,8 +119,9 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"source": [],
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -186,7 +140,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -195,16 +148,16 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"val sum = IntStream.range(0, 100).parallel().sum()\n",
|
||||
"\n",
|
||||
"println(sum)"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -213,8 +166,9 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"source": [],
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -233,7 +187,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -242,18 +195,18 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fun runLongTask(result: Int = 8): Int {\n",
|
||||
" Thread.sleep(100)\n",
|
||||
" println(\"Task complete: $result\")\n",
|
||||
" return result\n",
|
||||
"}"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -262,7 +215,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import java.util.concurrent.*\n",
|
||||
"\n",
|
||||
@ -275,7 +227,9 @@
|
||||
"}\n",
|
||||
"\n",
|
||||
"future.get()"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -294,7 +248,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -303,18 +256,18 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"interface Observable{\n",
|
||||
" fun onChange(callback: (Int) -> Unit)\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"val observable: Observable by lazy{ TODO() }"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -323,14 +276,15 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"val list: MutableList<Int> = mutableListOf<Int>()\n",
|
||||
"\n",
|
||||
"observable.onChange { \n",
|
||||
" list.add(it)\n",
|
||||
"}"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -349,7 +303,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -358,12 +311,12 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"source": [],
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -372,7 +325,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"val executor: ExecutorService = Executors.newFixedThreadPool(4)\n",
|
||||
"\n",
|
||||
@ -381,7 +333,9 @@
|
||||
" runLongTask(it)\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -400,7 +354,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -409,7 +362,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import kotlin.io.path.Path\n",
|
||||
"import kotlin.io.path.writeText\n",
|
||||
@ -423,7 +375,9 @@
|
||||
" .forEach { \n",
|
||||
" file.writeText(it)\n",
|
||||
" }"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -442,7 +396,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -451,7 +404,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"val cache = mutableMapOf<Int, Int>\n",
|
||||
"\n",
|
||||
@ -466,7 +418,9 @@
|
||||
" consumer(result)\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -500,7 +454,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -509,7 +462,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import kotlin.concurrent.*\n",
|
||||
"\n",
|
||||
@ -517,11 +469,12 @@
|
||||
" runLongTask()\n",
|
||||
"}\n",
|
||||
"t.join()"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -530,8 +483,9 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"source": [],
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -550,7 +504,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -559,7 +512,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"val future = executor.submit<Int>{\n",
|
||||
" runLongTask()\n",
|
||||
@ -567,7 +519,9 @@
|
||||
"\n",
|
||||
"future.get()\n",
|
||||
"future.cancel(true)"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -586,7 +540,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -595,7 +548,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import java.util.concurrent.*\n",
|
||||
"\n",
|
||||
@ -613,7 +565,9 @@
|
||||
"\n",
|
||||
"cf2.join()\n",
|
||||
"cf3.join()"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -632,7 +586,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -641,7 +594,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import java.util.concurrent.locks.*\n",
|
||||
"\n",
|
||||
@ -666,7 +618,9 @@
|
||||
"cf5.join()\n",
|
||||
"\n",
|
||||
"list"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@ -677,9 +631,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class A(val value: Int)\n",
|
||||
"class B(val value: Int)\n",
|
||||
@ -690,7 +642,9 @@
|
||||
"val combined = aFlow.zip(bFlow){ a, b->\n",
|
||||
" a.value + b.value\n",
|
||||
"}.debounce(2.seconds)"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@ -701,9 +655,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sealed class Event {\n",
|
||||
" class Open(val transactionId: Int): Event()\n",
|
||||
@ -732,7 +684,9 @@
|
||||
" }\n",
|
||||
"\n",
|
||||
"}"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -766,7 +720,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -775,7 +728,6 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import java.net.*\n",
|
||||
"import java.net.http.*\n",
|
||||
@ -807,7 +759,9 @@
|
||||
" }\n",
|
||||
" .thenAccept{ println(it.toList()) }\n",
|
||||
" .join()"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
@ -826,7 +780,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"datalore": {
|
||||
"hide_input_from_viewers": true,
|
||||
@ -835,8 +788,9 @@
|
||||
"type": "CODE"
|
||||
}
|
||||
},
|
||||
"source": [],
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"execution_count": null
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
Loading…
Reference in New Issue
Block a user