Last active
March 18, 2019 07:58
-
-
Save armcha/4afc4713f987bd778dec037bcba76a34 to your computer and use it in GitHub Desktop.
Decorator pattern simple exmple
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
fun main() { | |
val capitalizeDec = decorateCapitalize(::capitalize) | |
val text = capitalizeDec("HeLLo") | |
print(text) | |
} | |
fun capitalize(hello: String): String { | |
return hello.capitalize() | |
} | |
fun decorateCapitalize(body: (String) -> String): (String) -> String { | |
return fun(string: String): String { | |
return body(string.toLowerCase()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment