Created
November 29, 2012 18:47
-
-
Save nsfyn55/4171065 to your computer and use it in GitHub Desktop.
Composable Functions
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
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