Skip to content

Instantly share code, notes, and snippets.

@globulon
Created February 23, 2012 12:24
Show Gist options
  • Select an option

  • Save globulon/1892623 to your computer and use it in GitHub Desktop.

Select an option

Save globulon/1892623 to your computer and use it in GitHub Desktop.
Configuration
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