Last active
August 29, 2015 14:01
-
-
Save zhangxu/40a717e03e2abe123dac to your computer and use it in GitHub Desktop.
Scalaz Reader of Configuration
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
import scalaz.Reader | |
case class Configuration(hostname: String, port: Int, file: String) | |
case class ServerConnection(host: String, port: Int, file: String) | |
val config = Configuration("localhost", 8080, "index.html") | |
def configReader[A](f: Configuration => A): Reader[Configuration, A] = Reader { f } | |
val conn: scalaz.Kleisli[scalaz.Id.Id, Configuration, ServerConnection] = for { | |
h <- configReader { _.hostname } | |
p <- configReader { _.port } | |
o <- configReader { _.file } | |
} yield ServerConnection(h, p, o) | |
val serverConn = conn.run(config) // conn(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment