Last active
July 19, 2018 06:33
-
-
Save esafirm/e9ace1d3650e5d37b1b7662abb61b178 to your computer and use it in GitHub Desktop.
ADB Meetup #4 - Kotlin Puzzler
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"## Kotlin Puzzler - ADB Meetup 4\n", | |
"\n", | |
"#### Esa Firman\n", | |
"#### @Bukalapak" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"### Closure" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "-" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"val items = listOf(1,2,3)\n", | |
"items.forEach { \n", | |
" print(it)\n", | |
" if(it >= 2){\n", | |
" return\n", | |
" }\n", | |
"}\n", | |
"print(\"Complete!\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"### Property Equality" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "-" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"data class SomeClass(val value: String)\n", | |
"\n", | |
"val a get() = 1\n", | |
"val c get() = \"String\"\n", | |
"val b get() = SomeClass(\"Value\")\n", | |
"\n", | |
"println(a == a)\n", | |
"println(a === a)\n", | |
"println(b == b)\n", | |
"println(b === b)\n", | |
"println(c == c)\n", | |
"println(c === c)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"### Fun operator" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"fun and(a: Boolean, b: Boolean) = a && b \n", | |
"\n", | |
"val firstValue = 1 \n", | |
"val secondValue = 10\n", | |
"\n", | |
"print(and(firstValue < secondValue, firstValue > secondValue))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"### Throw something" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"class ADBException : Exception(\"This is ADB's fault!\")\n", | |
"\n", | |
"throw throw throw ADBException()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Two Lambda" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"typealias L = (String) -> Unit\n", | |
"\n", | |
"fun foo(one: L = {}, two: L = {}) {\n", | |
" one(\"one\")\n", | |
" two(\"two\")\n", | |
"}\n", | |
"\n", | |
"foo { print(it) }\n", | |
"foo({ print(it) })" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"celltoolbar": "Slideshow", | |
"kernelspec": { | |
"display_name": "Kotlin", | |
"language": "kotlin", | |
"name": "kotlin" | |
}, | |
"language_info": { | |
"file_extension": "kt", | |
"name": "kotlin" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment