Skip to content

Commit

Permalink
Add some notes, sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeden committed Jan 24, 2020
1 parent cd67479 commit 4babc74
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -53,3 +53,4 @@ google-services.json
freeline.py
freeline/
freeline_project_description.json
META-INF
5 changes: 4 additions & 1 deletion .vscode/settings.json
@@ -1,3 +1,6 @@
{
"code-runner.defaultLanguage": "kotlin"
"code-runner.defaultLanguage": "kotlin",
"editor.fontFamily": "Input Mono",
"editor.detectIndentation": false,
"code-runner.enableAppInsights": false
}
23 changes: 21 additions & 2 deletions README.md
@@ -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.
13 changes: 13 additions & 0 deletions SimVillage.kt
@@ -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"
}())
}

0 comments on commit 4babc74

Please sign in to comment.