README.md

# benedict

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

Benedict is a wrapper type over Dict that stores key-value pairs in ordered rings. See the example to understand it better.

```sh
gleam add benedict
```
```gleam
import benedict as bd

pub fn main() -> Nil {
  let assert Ok(bend) =
    // Create a new ring from a given list
    bd.ring_from_list([#(1, "one"), #(3, "three"), #(7, "seven")])
    // Add a new key-value pair before key marked 7
    |> bd.put_before(5, "five", mark: 7)

  let assert Ok(bend) =
    // Start q new ring with 2
    bd.put_aside(bend, 2, "two")
    // Add a new key-value pair after key marked 2
    |> bd.put_after(4, "four", mark: 2)
    // Make a mistake, add 0 after 2
    |> result.try(bd.put_after(_, 0, "zero", mark: 2))

  // Pop the key-value pair after 2 in the order
  let assert Ok(#(bend, 0, "zero")) = bd.pop_after(bend, 2)
  // Reinsert it correctly before 2
  let assert Ok(bend) = bd.put_before(bend, 0, "zero", mark: 2)

  let assert Ok([1, 3, 5, 7]) =
    // Get the key-value pairs in the ring headed by 1
    bd.ring_to_list(bend, head: 1)
    |> result.map(list.map(_, pair.first))
    as "odds are not in order"

  let assert Ok([0, 2, 4]) =
    // Get the key-value pairs in the ring headed by 0
    bd.ring_to_list(bend, head: 0)
    |> result.map(list.map(_, pair.first))
    as "evens are not in order"
}
```

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

## Development

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