Ark
Ark is a collection of small utilities for common Elixir patterns: things you find yourself rewriting across projects, too small to warrant a dedicated package but absent from the standard library.
The implementations are intentionally simple. They cover the common case well, but your project's needs may outgrow them, at which point reaching for a dedicated library or a custom solution is the right call.
Installation
def deps do
[
{:ark, "~> 0.13"},
]
endPlugins
Ark.Error
This module provides function to work errors as data.
Ark.Ok
This module provides base functions to work with ok/error tuples.
Ark.Paginator
This module provides a helper to build streams from paginated sources.
A user-supplied callback is called with an initial state and is expected to return the items for the current page along with the next state, until it signals that pagination is over.
pages = %{1 => [1, 2, 3], 2 => [4, 5, 6]}
{:ok, stream} =
Ark.Paginator.stream(1, fn page ->
case Map.get(pages, page, []) do
[] -> {:halt, []}
items -> {:cont, items, page + 1}
end
end)
Enum.to_list(stream)
# => [1, 2, 3, 4, 5, 6]Ark.Retry
This module provides base functions to retry operations.
Ark.StructAccess
This module provides a simple way to implement the Access behaviour for any struct.
Example
defmodule MyStruct do
defstruct [:k]
use Ark.StructAccess
end
s = %MyStruct{k: 1}
put_in(s.k, 2)
# => %MyStruct{k: 2}Ark.Timeout
Helpers to work with numerical timeout values
Documentation
The docs can be found at hexdocs.