Last active
April 30, 2018 09:17
-
-
Save Hiosdra/7d9ce2b035c968d0f535fb06b826fcc0 to your computer and use it in GitHub Desktop.
Gist as reply for https://devstyle.pl/2018/04/30/jak-i-po-co-pisac-funkcyjnie-w-c-sharp
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
//Type inference, global variable and function as object | |
var x = fun(x:Int, y:Int): Int { | |
return x + y | |
} | |
//Top level functions | |
fun main(args: Array<String>) { | |
println("Hello world") | |
} | |
//Function as parameter and expression-bodied methods | |
fun adding(a: Int, b: Int, addingFunction: (Int, Int) -> Int) = addingFunction.invoke(a, b) | |
fun example1() { | |
//Nested functions | |
fun increment(i: Int, incrementFunction: (i: Int) -> Int) = incrementFunction.invoke(i) | |
//Beautiful notation | |
val incrementedValue = increment(1) { it + 1 } | |
} | |
//Returning functions | |
fun returningFunction() = fun(s: String) = s.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment