Eparch

Package VersionHex DocsErlang CompatibleLicense

Built with Nix[Nix] Build & Test

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

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.

Looking for session types? The experimental session-types layer (the protocol grammar, duality witnesses, the specification/projection/codegen toolchain and the gen_statem protocol driver) now lives in pacta, which depends on this package. Eparch is the OTP wrapper, and nothing more.

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 .

The Erlang implementation is also a standalone rebar3 library under src/eparch/ffi. Gleam compiles the nested Erlang sources directly when it builds or publishes eparch, while these commands check the Erlang project on its own:

# Compile, run EUnit, and then Dialyzer
make ffi-check
# Regenerate src/eparch/ffi/deps.nix with rebar3_nix
make ffi-deps-nix
nix build .#eparch-ffi
  1. The Oxford Dictionary of Byzantium, Vol II.