Skip to content

Instantly share code, notes, and snippets.

@nsfyn55
Created November 29, 2012 18:47
Show Gist options
  • Save nsfyn55/4171065 to your computer and use it in GitHub Desktop.
Save nsfyn55/4171065 to your computer and use it in GitHub Desktop.
Composable Functions
object App {
def main (args: Array[String]){
val fp = candidate(_)
val f = decorate(fp,decorator) // F o G
println(f("Hello World"))
println(fp("Hello World"))
}
def candidate(s: String):String = {
"Transforming - " + s
}
def decorator(c: String=>String):(String=>String) = {
(s: String) => {
"****** " + c(s) + " *******"
}
}
def decorate[A,B](f:(A => B),f2:((A=>B)=>(A=>B))):(A=>B) = f2(f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment