# slabs
[](https://hex.pm/packages/slabs)
[](https://hexdocs.pm/slabs/)


This slab library in Gleam offers a robust data structure designed for managing collections of entries with immutability in mind. Each entry can be either vacant or occupied, allowing for efficient insertion and removal operations while ensuring safe access through well-defined functions. This library is ideal for scenarios where you need a reliable and performant way to handle dynamic collections without compromising on immutability.
```sh
gleam add slabs@1
```
```gleam
import slabs
import gleam/int
import gleam/io
pub fn main() -> Nil {
// [Occupied(45), Occupied(30), Occupied(20)], [0, 1, 2]
let #(slab, _) =
slabs.new()
|> slabs.insert_many([20, 30, 45])
// [Occupied(45), Occupied(30), Vacant(None)], 20
let assert Ok(#(slab, _)) = slabs.remove(slab, 0)
// [Occupied(45), Occupied(30), Occupied(15)], 0
let #(slab, index) =
slab
|> slabs.insert(15)
let assert option.Some(value) = slabs.get(slab, index)
// 15
value
|> int.to_string
|> io.println
}
```
Further documentation can be found at <https://hexdocs.pm/slabs>.