module Relay
  # Uniform error-handling shape used across the whole codebase: every
  # fallible operation returns a Result; exceptions are reserved for
  # programmer errors, never expected failures.
  Result = Struct.new(:ok, :value, :error) do
    def self.ok(value = nil) = new(true, value, nil)
    def self.err(error) = new(false, nil, error)

    def ok? = ok
    def err? = !ok
  end
end
