Skip to content

Instantly share code, notes, and snippets.

@armcha
Last active March 18, 2019 07:58
Show Gist options
  • Select an option

  • Save armcha/4afc4713f987bd778dec037bcba76a34 to your computer and use it in GitHub Desktop.

Select an option

Save armcha/4afc4713f987bd778dec037bcba76a34 to your computer and use it in GitHub Desktop.
Decorator pattern simple exmple
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