Update notebooks

This commit is contained in:
Alexander Nozik 2024-12-08 12:38:44 +03:00
parent 5dfd67b563
commit 85b1931673
2 changed files with 269 additions and 263 deletions

View File

@ -138,7 +138,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"source": "println(\"This is a string with \\$\")", "source": "println(\"This is a string with \\$a\")",
"metadata": { "metadata": {
"datalore": { "datalore": {
"node_id": "hm9iYlWj1B2S0469GtxDrf", "node_id": "hm9iYlWj1B2S0469GtxDrf",
@ -157,13 +157,16 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"println(\"\"\"\n", "println(\n",
" \"\"\"\n",
" \\\\\\\n",
" This is a \n", " This is a \n",
" multi\n", " multi\n",
" line\n", " line\n",
" raw\n", " raw\n",
" string\n", " string\n",
"\"\"\".trimIndent())" "\"\"\".trimIndent()\n",
")"
], ],
"metadata": { "metadata": {
"datalore": { "datalore": {
@ -182,9 +185,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": "println(\"\"\"This is a raw string number ${number + 1} with \\ and ${'$'} \"\"\")",
"println(\"\"\"This is a raw string number ${number+1} with \\ and ${'$'} \"\"\")"
],
"metadata": { "metadata": {
"datalore": { "datalore": {
"node_id": "KDL3D9lOVn6vX3iTAY50gb", "node_id": "KDL3D9lOVn6vX3iTAY50gb",
@ -295,6 +296,20 @@
"outputs": [], "outputs": [],
"execution_count": null "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", "cell_type": "markdown",
"source": [ "source": [
@ -384,6 +399,7 @@
"fun doSomethingSpecial() {\n", "fun doSomethingSpecial() {\n",
" val base = \"base\"\n", " val base = \"base\"\n",
" val special = \"special\"\n", " val special = \"special\"\n",
"\n",
" /**\n", " /**\n",
" * This one is inside another function\n", " * This one is inside another function\n",
" */\n", " */\n",
@ -462,7 +478,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"fun returnUnit(): Unit {\n", "fun returnUnit(): Unit {\n",
" // no return statement `Unit` is returned implicitly\n", " // no return statement `Unit` is returned implicitly\n",
" val b = Unit\n", " val b = Unit\n",
@ -520,9 +535,10 @@
"}\n", "}\n",
"\n", "\n",
"doSomethingWithDefault()\n", "doSomethingWithDefault()\n",
"doSomethingWithDefault(4)\n",
"doSomethingWithDefault(2, \"aaa\")\n", "doSomethingWithDefault(2, \"aaa\")\n",
"doSomethingWithDefault(b = \"fff\", a = 8)\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" "doSomethingWithDefault(a = 2, \"fff\")// don't do that"
], ],
"metadata": { "metadata": {
@ -591,7 +607,7 @@
"\n", "\n",
"//@JvmOverloads\n", "//@JvmOverloads\n",
"@JvmName(\"functionWithDefaultParameters\")\n", "@JvmName(\"functionWithDefaultParameters\")\n",
"fun functionWithParameters(a: Int = 2){\n", "fun functionWithParameters(a: Int = 2) { // don't do that\n",
" println(\"with default\")\n", " println(\"with default\")\n",
"}\n", "}\n",
"\n", "\n",
@ -717,13 +733,16 @@
"source": [ "source": [
"//Interfaces and objects\n", "//Interfaces and objects\n",
"\n", "\n",
"interface AnInterface {\n", "fun interface AnInterface {\n",
" val a: Int\n", " val a: Int\n",
" get() = 4\n", " get() = 4\n",
"\n",
" // set(value){\n", " // set(value){\n",
" // println(value)\n", " // println(value)\n",
" // }\n", " // }\n",
" fun doSomething() //= println(\"From interface\")\n", " fun doSomething() //= println(\"From interface\")\n",
"\n",
" fun doSomething2() = Unit\n",
"}\n", "}\n",
"\n", "\n",
"abstract class AnAbstractClass(override val a: Int) : AnInterface {\n", "abstract class AnAbstractClass(override val a: Int) : AnInterface {\n",
@ -761,6 +780,11 @@
" */\n", " */\n",
"val anonymous = object : AnInterface {\n", "val anonymous = object : AnInterface {\n",
" override fun doSomething(): Unit = TODO(\"Not yet implemented\")\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", "\n",
"/**\n", "/**\n",
@ -994,7 +1018,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"val res: Result<Int> = runCatching<Int> {\n", "val res: Result<Int> = runCatching<Int> {\n",
" //error(\"Error happened\")\n", " //error(\"Error happened\")\n",
" 4\n", " 4\n",
@ -1098,6 +1121,19 @@
"outputs": [], "outputs": [],
"execution_count": null "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", "cell_type": "markdown",
"source": [ "source": [
@ -1116,13 +1152,16 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"class SimpleClass(val a: Int, val b: Double, c: Double) {\n", "class SimpleClass(val a: Int, val b: Double, c: Double) {\n",
" override fun toString() = \"SimpleClass(a=$a, b=$b)\"\n", " override fun toString() = \"SimpleClass(a=$a, b=$b)\"\n",
"}\n", "}\n",
"\n", "\n",
"\n", "\n",
"data class DataClass(val a: Int, var b: Double /*, d: Double */) {\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", " val c get() = b + 1\n",
"}\n", "}\n",
"\n", "\n",
@ -1237,6 +1276,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"import java.io.File\n",
"\n", "\n",
"/**\n", "/**\n",
" * Safe call and elvis operator\n", " * Safe call and elvis operator\n",
@ -1311,7 +1351,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"/**\n", "/**\n",
" * Dart-like (?=) nullable assignment\n", " * Dart-like (?=) nullable assignment\n",
" */\n", " */\n",
@ -1405,7 +1444,7 @@
{ {
"metadata": {}, "metadata": {},
"cell_type": "code", "cell_type": "code",
"source": "", "source": "0.0..8.0 intersect 2.9..6.1",
"outputs": [], "outputs": [],
"execution_count": null "execution_count": null
}, },
@ -1467,7 +1506,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"/**\n", "/**\n",
" * Extension property (must be virtual)\n", " * Extension property (must be virtual)\n",
" */\n", " */\n",
@ -1499,7 +1537,14 @@
" }\n", " }\n",
" }\n", " }\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", "\n",
"map.a = \"6\"\n", "map.a = \"6\"\n",
"\n", "\n",
@ -1519,7 +1564,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"/**\n", "/**\n",
" * Extension variable (also must be virtual)\n", " * Extension variable (also must be virtual)\n",
" */\n", " */\n",
@ -1617,7 +1661,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"//using `run`\n", "//using `run`\n",
"getAClass()?.takeIf { it.a.isNotEmpty() }?.run {\n", "getAClass()?.takeIf { it.a.isNotEmpty() }?.run {\n",
" // the same as above\n", " // the same as above\n",
@ -1650,7 +1693,15 @@
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"//Don't do that\n", "//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": [], "outputs": [],
"execution_count": null "execution_count": null
@ -1683,6 +1734,10 @@
" */\n", " */\n",
"fun getAndIncrement() = i.also { i += 1 } //don't do that\n", "fun getAndIncrement() = i.also { i += 1 } //don't do that\n",
"\n", "\n",
"fun incrementAndPring(arg: Int) = (arg + 1).also{\n",
" println(it)\n",
"}\n",
"\n",
"println(getAndIncrement())\n", "println(getAndIncrement())\n",
"println(i)" "println(i)"
], ],
@ -1700,7 +1755,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"class Rectangle {\n", "class Rectangle {\n",
" var length: Number = 0\n", " var length: Number = 0\n",
" var breadth: Number = 0\n", " var breadth: Number = 0\n",
@ -1740,6 +1794,13 @@
"outputs": [], "outputs": [],
"execution_count": null "execution_count": null
}, },
{
"metadata": {},
"cell_type": "code",
"source": "",
"outputs": [],
"execution_count": null
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"source": [ "source": [
@ -1790,7 +1851,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"/**\n", "/**\n",
" * This one creates a mutable list\n", " * This one creates a mutable list\n",
" */\n", " */\n",
@ -1815,7 +1875,6 @@
"metadata": {}, "metadata": {},
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"//don't do that ever\n", "//don't do that ever\n",
"fun doBadThingWithList(list: List<String>): List<String> = (list as MutableList<String>).apply { add(\"something\") }\n", "fun doBadThingWithList(list: List<String>): List<String> = (list as MutableList<String>).apply { add(\"something\") }\n",
"\n", "\n",
@ -1895,7 +1954,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"/**\n", "/**\n",
" * This one creates a mutable ArrayList.\n", " * This one creates a mutable ArrayList.\n",
" */\n", " */\n",
@ -1923,7 +1981,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"//Bonus\n", "//Bonus\n",
"\n", "\n",
"val lambdaList = List(3) { it.toString() }\n", "val lambdaList = List(3) { it.toString() }\n",
@ -1934,6 +1991,7 @@
" add(8)\n", " add(8)\n",
" remove(8)\n", " remove(8)\n",
"}\n", "}\n",
"\n",
"builderList" "builderList"
], ],
"metadata": { "metadata": {
@ -2055,7 +2113,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"//val entry: MutableMap.MutableEntry<String, String> = map.iterator().next()\n", "//val entry: MutableMap.MutableEntry<String, String> = map.iterator().next()\n",
"\n", "\n",
"//map.entries.first().component2()\n", "//map.entries.first().component2()\n",
@ -2083,7 +2140,12 @@
}, },
{ {
"cell_type": "code", "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": { "metadata": {
"datalore": { "datalore": {
"node_id": "s1Q65aNWb9YNBZOgxmjotW", "node_id": "s1Q65aNWb9YNBZOgxmjotW",
@ -2098,7 +2160,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"val (a, b) = Pair(1, 2)\n", "val (a, b) = Pair(1, 2)\n",
"\n", "\n",
"val coord = doubleArrayOf(0.0, 1.0, 2.0)\n", "val coord = doubleArrayOf(0.0, 1.0, 2.0)\n",
@ -2158,7 +2219,6 @@
"}\n", "}\n",
"\n", "\n",
"\n", "\n",
"\n",
"val obj = AClassWithList()\n", "val obj = AClassWithList()\n",
"\n", "\n",
"// obj.b = 10.0 //error\n", "// obj.b = 10.0 //error\n",
@ -2178,9 +2238,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"source": [ "source": "## Wrap mutable logic / Kotlin builder pattern",
"## Wrap mutable logic"
],
"attachments": {}, "attachments": {},
"metadata": { "metadata": {
"datalore": { "datalore": {
@ -2226,7 +2284,7 @@
" fun build() = ImmutableObject(a, b, c)\n", " fun build() = ImmutableObject(a, b, c)\n",
"}\n", "}\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", " ImmutableObjectBuilder(a).apply(block).build()\n",
"\n", "\n",
"ImmutableObject(\"aValue\") {\n", "ImmutableObject(\"aValue\") {\n",
@ -2259,7 +2317,6 @@
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"val emailsList = emptyList<String>()\n", "val emailsList = emptyList<String>()\n",
"\n", "\n",
"// When used directly infix in operator checks if the element is contained in a collection\n", "// When used directly infix in operator checks if the element is contained in a collection\n",
@ -2310,7 +2367,6 @@
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"// Another (different) use of `in` is iteration over range or collection using\n", "// Another (different) use of `in` is iteration over range or collection using\n",
"// using `operator fun iterator`\n", "// using `operator fun iterator`\n",
"\n", "\n",
@ -2385,6 +2441,7 @@
" //.onEach { println(it) }\n", " //.onEach { println(it) }\n",
" //.sumOf { it } //use one of reduce operations\n", " //.sumOf { it } //use one of reduce operations\n",
" .reduce { acc: Int, i: Int -> acc + i }\n", " .reduce { acc: Int, i: Int -> acc + i }\n",
" //.fold(0.0) { acc: Double, i: Int -> acc + i }\n",
"\n", "\n",
"result" "result"
], ],
@ -2534,7 +2591,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"open class Bad {\n", "open class Bad {\n",
" val value: Int = requestValue()\n", " val value: Int = requestValue()\n",
"\n", "\n",
@ -2586,8 +2642,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"\n",
"//Factory functions are preferred to the initialization logic\n", "//Factory functions are preferred to the initialization logic\n",
"\n", "\n",
"data class Good internal constructor(val value: Int) {\n", "data class Good internal constructor(val value: Int) {\n",
@ -2599,11 +2653,10 @@
" companion object\n", " companion object\n",
"}\n", "}\n",
"\n", "\n",
"fun requestValue(): Int = TODO()\n", "private fun requestValue(): Int = TODO()\n",
"\n", "\n",
"// This is the factory-function\n", "// This is the factory-function\n",
"fun Good() = Good(requestValue())\n", "fun Good(): Good = Good(requestValue())\n",
"\n",
"\n", "\n",
"// additional constructor-like builders could be added to the companion\n", "// additional constructor-like builders could be added to the companion\n",
"\n", "\n",
@ -2649,16 +2702,18 @@
" 22\n", " 22\n",
" }\n", " }\n",
"\n", "\n",
" val getterValue: Int get(){\n", " val getterValue: Int\n",
" get() {\n",
" println(\"got\")\n", " println(\"got\")\n",
" return 33\n", " return 33\n",
" }\n", " }\n",
"}\n", "}\n",
"\n",
"val lazyClass = ClassWithALazyProperty()\n", "val lazyClass = ClassWithALazyProperty()\n",
"lazyClass.lazyValue\n", "println(lazyClass.lazyValue)\n",
"lazyClass.lazyValue\n", "println(lazyClass.lazyValue)\n",
"lazyClass.getterValue\n", "println(lazyClass.getterValue)\n",
"lazyClass.getterValue" "println(lazyClass.getterValue)"
], ],
"metadata": { "metadata": {
"datalore": { "datalore": {
@ -2674,7 +2729,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"//Using other delegates\n", "//Using other delegates\n",
"val map = mutableMapOf(\"a\" to 1, \"b\" to 2)\n", "val map = mutableMapOf(\"a\" to 1, \"b\" to 2)\n",
"\n", "\n",
@ -2713,7 +2767,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"/**\n", "/**\n",
" * Definition of inline function\n", " * Definition of inline function\n",
" */\n", " */\n",
@ -2749,7 +2802,6 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"\n",
"/**\n", "/**\n",
" * Using inline function for type reification during the compile time\n", " * Using inline function for type reification during the compile time\n",
" */\n", " */\n",

View File

@ -2,7 +2,6 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -11,10 +10,11 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"%use coroutines" "%use coroutines"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -40,7 +40,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -49,16 +48,16 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"repeat(10){\n", "repeat(10){\n",
" println(\"Line number $it\")\n", " println(\"Line number $it\")\n",
"}" "}"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -67,12 +66,13 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"import java.util.stream.*\n", "import java.util.stream.*\n",
"\n", "\n",
"IntStream.range(0, 100).sum()" "IntStream.range(0, 100).sum()"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -91,7 +91,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -100,64 +99,18 @@
"type": "CODE" "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": [ "source": [
"val list = (0..100).toMutableList()\n", "val list = (0..100).toMutableList()\n",
"\n", "\n",
"list.forEach {\n", "list.forEach {\n",
" if(it % 2 == 0) list.remove(it)\n", " if(it % 2 == 0) list.remove(it)\n",
"}" "}"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -166,8 +119,9 @@
"type": "CODE" "type": "CODE"
} }
}, },
"source": [],
"outputs": [], "outputs": [],
"source": [] "execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -186,7 +140,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -195,16 +148,16 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"val sum = IntStream.range(0, 100).parallel().sum()\n", "val sum = IntStream.range(0, 100).parallel().sum()\n",
"\n", "\n",
"println(sum)" "println(sum)"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -213,8 +166,9 @@
"type": "CODE" "type": "CODE"
} }
}, },
"source": [],
"outputs": [], "outputs": [],
"source": [] "execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -233,7 +187,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -242,18 +195,18 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"fun runLongTask(result: Int = 8): Int {\n", "fun runLongTask(result: Int = 8): Int {\n",
" Thread.sleep(100)\n", " Thread.sleep(100)\n",
" println(\"Task complete: $result\")\n", " println(\"Task complete: $result\")\n",
" return result\n", " return result\n",
"}" "}"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -262,7 +215,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"import java.util.concurrent.*\n", "import java.util.concurrent.*\n",
"\n", "\n",
@ -275,7 +227,9 @@
"}\n", "}\n",
"\n", "\n",
"future.get()" "future.get()"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -294,7 +248,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -303,18 +256,18 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"interface Observable{\n", "interface Observable{\n",
" fun onChange(callback: (Int) -> Unit)\n", " fun onChange(callback: (Int) -> Unit)\n",
"}\n", "}\n",
"\n", "\n",
"val observable: Observable by lazy{ TODO() }" "val observable: Observable by lazy{ TODO() }"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -323,14 +276,15 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"val list: MutableList<Int> = mutableListOf<Int>()\n", "val list: MutableList<Int> = mutableListOf<Int>()\n",
"\n", "\n",
"observable.onChange { \n", "observable.onChange { \n",
" list.add(it)\n", " list.add(it)\n",
"}" "}"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -349,7 +303,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -358,12 +311,12 @@
"type": "CODE" "type": "CODE"
} }
}, },
"source": [],
"outputs": [], "outputs": [],
"source": [] "execution_count": null
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -372,7 +325,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"val executor: ExecutorService = Executors.newFixedThreadPool(4)\n", "val executor: ExecutorService = Executors.newFixedThreadPool(4)\n",
"\n", "\n",
@ -381,7 +333,9 @@
" runLongTask(it)\n", " runLongTask(it)\n",
" }\n", " }\n",
"}" "}"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -400,7 +354,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -409,7 +362,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"import kotlin.io.path.Path\n", "import kotlin.io.path.Path\n",
"import kotlin.io.path.writeText\n", "import kotlin.io.path.writeText\n",
@ -423,7 +375,9 @@
" .forEach { \n", " .forEach { \n",
" file.writeText(it)\n", " file.writeText(it)\n",
" }" " }"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -442,7 +396,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -451,7 +404,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"val cache = mutableMapOf<Int, Int>\n", "val cache = mutableMapOf<Int, Int>\n",
"\n", "\n",
@ -466,7 +418,9 @@
" consumer(result)\n", " consumer(result)\n",
" }\n", " }\n",
"}" "}"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -500,7 +454,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -509,7 +462,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"import kotlin.concurrent.*\n", "import kotlin.concurrent.*\n",
"\n", "\n",
@ -517,11 +469,12 @@
" runLongTask()\n", " runLongTask()\n",
"}\n", "}\n",
"t.join()" "t.join()"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -530,8 +483,9 @@
"type": "CODE" "type": "CODE"
} }
}, },
"source": [],
"outputs": [], "outputs": [],
"source": [] "execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -550,7 +504,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -559,7 +512,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"val future = executor.submit<Int>{\n", "val future = executor.submit<Int>{\n",
" runLongTask()\n", " runLongTask()\n",
@ -567,7 +519,9 @@
"\n", "\n",
"future.get()\n", "future.get()\n",
"future.cancel(true)" "future.cancel(true)"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -586,7 +540,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -595,7 +548,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"import java.util.concurrent.*\n", "import java.util.concurrent.*\n",
"\n", "\n",
@ -613,7 +565,9 @@
"\n", "\n",
"cf2.join()\n", "cf2.join()\n",
"cf3.join()" "cf3.join()"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -632,7 +586,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -641,7 +594,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"import java.util.concurrent.locks.*\n", "import java.util.concurrent.locks.*\n",
"\n", "\n",
@ -666,7 +618,9 @@
"cf5.join()\n", "cf5.join()\n",
"\n", "\n",
"list" "list"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -677,9 +631,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"class A(val value: Int)\n", "class A(val value: Int)\n",
"class B(val value: Int)\n", "class B(val value: Int)\n",
@ -690,7 +642,9 @@
"val combined = aFlow.zip(bFlow){ a, b->\n", "val combined = aFlow.zip(bFlow){ a, b->\n",
" a.value + b.value\n", " a.value + b.value\n",
"}.debounce(2.seconds)" "}.debounce(2.seconds)"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -701,9 +655,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"sealed class Event {\n", "sealed class Event {\n",
" class Open(val transactionId: Int): Event()\n", " class Open(val transactionId: Int): Event()\n",
@ -732,7 +684,9 @@
" }\n", " }\n",
"\n", "\n",
"}" "}"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -766,7 +720,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -775,7 +728,6 @@
"type": "CODE" "type": "CODE"
} }
}, },
"outputs": [],
"source": [ "source": [
"import java.net.*\n", "import java.net.*\n",
"import java.net.http.*\n", "import java.net.http.*\n",
@ -807,7 +759,9 @@
" }\n", " }\n",
" .thenAccept{ println(it.toList()) }\n", " .thenAccept{ println(it.toList()) }\n",
" .join()" " .join()"
] ],
"outputs": [],
"execution_count": null
}, },
{ {
"attachments": {}, "attachments": {},
@ -826,7 +780,6 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"datalore": { "datalore": {
"hide_input_from_viewers": true, "hide_input_from_viewers": true,
@ -835,8 +788,9 @@
"type": "CODE" "type": "CODE"
} }
}, },
"source": [],
"outputs": [], "outputs": [],
"source": [] "execution_count": null
} }
], ],
"metadata": { "metadata": {