Ark

hex.pm VersionBuild StatusLicense

Ark is a collection of small utilities useful for prototyping, testing, and working with Elixir common patterns.

Installation

def deps do
  [
    {:ark, "~> 0.12"},
  ]
end

Plugins

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.PubSub

This module provides a simple pub-sub mechanism.

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}

Documentation

The docs can be found at hexdocs.