Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,4 @@ google-services.json | |
freeline.py | ||
freeline/ | ||
freeline_project_description.json | ||
META-INF |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"code-runner.defaultLanguage": "kotlin" | ||
"code-runner.defaultLanguage": "kotlin", | ||
"editor.fontFamily": "Input Mono", | ||
"editor.detectIndentation": false, | ||
"code-runner.enableAppInsights": false | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
# learning-kotlin | ||
# General | ||
|
||
- A function that returns nothing is implicitly returning the `Unit` type | ||
- A function that never returns at all is implicitly returning the `Nothing` type (e.g. the `TODO()` function) | ||
|
||
# Terminology | ||
|
||
### Single-Expression Functions | ||
|
||
Function's that only evaluate a single expression can have their return type, curly braces, and return statement removed. | ||
|
||
```kotlin | ||
val x = 9 | ||
// Verbose | ||
fun sayHello(name: String) { | ||
println("Hello, $name") | ||
} | ||
|
||
// Single-expression function | ||
fun sayHello(name: String) = println("Hello, $name") | ||
``` | ||
|
||
# Tidbits | ||
|
||
File-level functions in Kotlin are represented in Kotlin as static methods on a class with a name based on the file in which they are declared. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Chapter 5 - Anaonymous Functions & the Function Type | ||
* SimVillage | ||
*/ | ||
|
||
fun main(args: Array<String>) { | ||
print("HI!") | ||
|
||
println({ | ||
val currentYear = 2020 | ||
"Welcome to SimVillage, Mayor! ©$currentYear" | ||
}()) | ||
} |