Skip to content

tonivade/purecfg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PureCFG

Inspired by this presentation

Objectives

  • Create a pure functional library to load configuration from different sources, like properties files, json, yaml or any other source.
  • Allow to switch from sources without changing the program.
  • Self documented.
  • Type safe.

Now it supports properties and toml files.

Example

[server]
  host = "localhost"
  port = 8080
record HostAndPort(String host, Integer port) { }

var readHostAndPort = PureCFG.map2(PureCFG.readString("host"), PureCFG.readInt("port"), HostAndPort::new);
var program = PureCFG.readConfig("server", readHostAndPort);

var config = program.unsafeRun(Source.fromToml("config.toml"));
assertEquals(new HostAndPort("localhost", 8080), config);

License

Distributed under MIT License