Created
February 23, 2012 12:24
-
-
Save globulon/1892623 to your computer and use it in GitHub Desktop.
Configuration
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
| case class Config[T](data: T) | |
| implicit object ApplicativeConfig extends Applicative[Config] { | |
| def apply[T](data: T) = Config(data) | |
| def flatten[T](m: Config[Config[T]]) = m.data | |
| def map[T, P >: T, U](source: Config[T])(f: (P) => U) = Config(f(source.data)) | |
| } | |
| case class Connection() | |
| case class Datastore() | |
| case class Application() | |
| case class Environment(datastore: Datastore, application: Application) | |
| def connection(map: Map[String, String]): Config[Connection] = Config(Connection()) | |
| def datastore(conn: Config[Connection])(map: Map[String, String]): Config[Datastore] = Config(Datastore()) | |
| def application(map: Map[String, String]): Config[Application] = Config(Application()) | |
| def build = (a: Application, d: Datastore) => Environment(d, a) | |
| def configBuilder = for { | |
| conn <- connection _ | |
| store <- datastore(conn) _ | |
| app <- application _ | |
| } yield (build:@:app:*:store) | |
| println(configBuilder(Map())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment