README.md

# fiction

[![Package Version](https://img.shields.io/hexpm/v/fiction)](https://hex.pm/packages/fiction)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/fiction/)

A library to help combine app configuration from multiple sources into a single record. This core is pure gleam, though most useful providers will have target-specific code.

Heavily inspired by [Figment](https://crates.io/crates/figment)


```sh
gleam add fiction@1
```
```gleam
import gleam/dynamic/decode
import fiction

type Config {
  Config(
    port: Int,
    host: String
  )
}

// The decoder can provide defaults if you want
fn config_decoder() {
  use port <- decode.optional_field("port", 5432, decode.int)
  use host <- decode.field("host", decode.string)

  decode.success(Config(port:, host:))
}

pub fn main() -> Nil {
  let assert Ok(config) =
    fiction.new()
    |> fiction.join(get_config_from_file)
    |> fiction.merge(get_config_from_env)
    |> fiction.extract(with: config_decoder())
}

// providers are just plain functions that return a Result(Dict(String, Value), String)
fn get_config_from_file() {
  // this can do basically anything
}

fn get_config_from_env() {
  // try a different source
}
```

Further documentation can be found at <https://hexdocs.pm/fiction>.

## Development

```sh
gleam test  # Run the tests
```