Quick Reference

View Source

< Syntax In Depth | Up: Introduction | Index | Performance >

comp syntax

comp do
  x <- effect()            # effectful bind
  {:ok, y} = expr          # pure pattern match
  z = expr                 # pure assignment
end

Handler installation

comp |> Eff1.with_handler(args) |> Eff2.with_handler(args) |> Comp.run!()

Handler order is independent. EffectLogger must be innermost.

Effect overview

State & Environment

EffectOperationsHandler
Stateget/0,1, put/1,2, modify/1,2, gets/1,2State.with_handler(comp, initial, opts)
Readerask/0,1, asks/1,2, local/2,3Reader.with_handler(comp, value, opts)
Writertell/1,2, peek/0,1, listen/1,2, pass/1,2, censor/2,3Writer.with_handler(comp, initial, opts)

Error & Resources

EffectOperationsHandler
Throwthrow/1, catch_error/2Throw.with_handler(comp)
Bracketbracket/3, bracket_/3, finally/2Pure combinator

Value Generation

EffectOperationsProd handlerTest handler
Freshfresh_uuid/0Fresh.with_uuid7_handler()Fresh.with_test_handler()
Randomrandom/0, random_int/2, random_element/1, shuffle/1Random.with_handler()Random.with_seed_handler(seed: N)

Collections

Combinatorfx_map/2, fx_reduce/3, fx_each/2, fx_filter/2
FxListFull Yield support
FxFasterListHigher perf, limited Yield

Concurrency

EffectKey opsHandler
FiberPoolfiber/1, await/1, await!/1, await_all/1, scope/1,2, map/2FiberPool.with_handler(comp)
Channelnew/1, put/2, take/1, close/1, put_async/2, take_async/1Channel.with_handler(comp)
Brookfrom_enum/1, map/2,3, filter/2,3, each/2, reduce/3, to_list/1Pure combinator
Parallelall/1, race/1, map/2Parallel.with_handler(comp)
AtomicStateget/0,1, put/1,2, modify/1,2, cas/2,3AtomicState.with_agent_handler(comp, init)

Persistence

EffectOperationsHandler
Commandexecute/1Command.with_handler(comp, fn)
Transactiontransact/1, rollback/1, try_transact/1Transaction.Ecto.with_handler(repo) / Transaction.Noop.with_handler(comp)

External Integration

ModuleKey functions
Portrequest/3, request!/3; with_handler/2,3, with_test_handler/2,3, with_fn_handler/2,3, with_stateful_handler/4
Port.EffectfulFacadedefcallback, __key__ helpers
Repoinsert/1,2, update/1,2, delete/1,2, get/2,3, get_by/2,3, all/1,2, one/1,2 + bangs
Adapteruse Skuld.Adapter, contract: M, impl: I, stack: &f/1
AsyncCoroutinerun/2,3, run_sync/2,3, cancel/1,2

Logging & Durability

ModuleKey functions
EffectLoggerwith_logging/1,2,3, with_resume/3,4, mark_loop/1
SerializableCoroutinenew/2, get_log/1, serialize/1, deserialize/1

Query & Batching

ModuleKey functions
Query.Contractdeffetch, with_executor/2,3, with_cached_executor/2,3, with_cached_executors/2
QueryBlockquery do ... end, defquery, defqueryp

Running computations

FunctionBehaviour
Comp.run(comp)Returns {result, env}
Comp.run!(comp)Raises on Throw/Suspend

< Syntax In Depth | Up: Introduction | Index | Performance >