Created
April 2, 2015 23:22
-
-
Save stefanobaghino/5bd528f7d5ba7fb6262e to your computer and use it in GitHub Desktop.
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
trait Greeter { | |
def greet(who: String): String = | |
s"hello, $who" | |
} | |
import scala.io.AnsiColor._ | |
object Colorful { | |
def endlessRainbow: Stream[String] = RED #:: YELLOW #:: GREEN #:: CYAN #:: BLUE #:: endlessRainbow | |
} | |
trait Colorful { | |
import Colorful._ | |
def colorize(message: String): String = | |
endlessRainbow. | |
zip(message). | |
flatMap { | |
case (color: String, char: Char) => s"$color$char" | |
}.mkString ++ RESET | |
} | |
trait ColorfulGreeter extends Colorful with Greeter { | |
val colorfulGreeting = greet _ andThen colorize _ | |
} | |
object UnicornHello extends App with ColorfulGreeter { | |
println(colorfulGreeting("world")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment