Eparch

Package Version Hex Docs License

Built with Nix [Nix] Build & Test

EPARCH OF THE CITY (ἔπαρχος τῆς πόλεως), successor of the late Roman URBAN PREFECT, the governor of Constantinople. 1

1

The Oxford Dictionary of Byzantium, Vol II.

Eparch is a Gleam library that wraps certain Erlang/OTP behaviours with a type-safe API, making your byzantine systems shine with a great type system.

Supported OTP Behaviours

ModuleWrapsPurpose
eparch/state_machinegen_statemType-safe finite state machines
eparch/event_managergen_eventBroadcast event managers with dynamic handlers

Full API reference: https://hexdocs.pm/eparch.

Key Differences from gen_statem

Erlang’s gen_statemeparch/state_machine
Separate handle_call, handle_cast, handle_infoSingle handler dispatching on a unified Event type
Raw action tuplesType-safe Action values
state_enter always onOpt-in via with_state_enter()
Multiple return tuple formatsSingle Step type (NextState, KeepState, Stop)

Key Differences from gen_event

Erlang’s gen_eventeparch/event_manager
Separate handler callback module per handlerSingle Handler builder (new_handler/2, on_terminate/2)
Handler identified by {Module, Id} tupleOpaque HandlerRef returned by add_handler
handle_call for per-handler queriesEmbed process.Subject(reply) in your event type instead
add_sup_handleradd_supervised_handler

Installation

gleam add eparch

Usage

See the Quick Start guide for full walkthroughs, or run some of the example projects that live in the examples/ directory.

Development

The project uses devenv and Nix for a hermetic development environment:

nix develop

Or, if you are already using direnv:

direnv allow .
Search Document