Skip to content

Instantly share code, notes, and snippets.

@Atternatt
Last active September 21, 2017 04:55
Show Gist options
  • Save Atternatt/e30e0e68cbade9985f39b1df859e8687 to your computer and use it in GitHub Desktop.
Save Atternatt/e30e0e68cbade9985f39b1df859e8687 to your computer and use it in GitHub Desktop.
monads
var sum4 : (Int) -> Int = { value -> value + 4 }
var div2 : (Int) -> Int = { value -> value / 2 }
sum4(4) //return 8
div2(4) //return 2
listOf(3,4,6,8,10)
.map(sum4)
.map(div2)
//[3, 4, 5, 6, 7]
fun hello(name: String, textDecorator: () -> String): String {
return "hello $name ${textDecorator()}"
}
hello("marc") {
"you are awesome!"
}
// es lo mismo que
hello("marc", {"you are awesome"})
//hello marc You are awesome!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment