A package for keeping your JSON encoders and decoders in sync.
✨ This project is written in pure Gleam so you can use it anywhere Gleam runs: Erlang, Elixir, Node, Deno, and the browser!
import gleam_community/codec
pub type Colour {
RGB(Int, Int, Int)
Name(String)
}
pub fn colour_codec() {
codec.custom2(fn(rgb, name, value) {
case value {
RGB(r, g, b) -> rgb(r, g, b)
Name(n) -> name(n)
}
})
|> codec.variant3("RGB", RGB, codec.int(), codec.int(), codec.int())
|> codec.variant1("Name", Name, codec.string())
|> codec.construct
}
gleam-community
packages are published to hex.pm
with the prefix gleam_community_
. You can add them to your Gleam projects directly:
gleam add gleam_community_codec
The docs can be found over at hexdocs.pm.