Quick Start
Install
Add the core library (and ZIO, which Mechanoid marks as provided). Use the version shown in the site chrome (header / footer); the hub index install snippets stay in sync with releases.
libraryDependencies += "rocks.earlyeffect" %% "mechanoid" % "<version from site chrome>"
libraryDependencies += "dev.zio" %% "zio" % "2.1.26"
// Optional PostgreSQL persistence
libraryDependencies += "rocks.earlyeffect" %% "mechanoid-postgres" % "<version from site chrome>"
Release tags are v*. Maven Central badges on the GitHub repo
also track the latest publish.
Define and run
assembly validates transitions at compile time. Machine(...) makes the assembly runnable.
start gives you an in-memory FSMRuntime scoped to the ZIO scope.
{
import mechanoid.*
import zio.*
enum OrderState derives Finite:
case Pending, Paid, Shipped
enum OrderEvent derives Finite:
case Pay, Ship
import OrderState.*, OrderEvent.*
val orderMachine = Machine(
assembly[OrderState, OrderEvent](
Pending via Pay to Paid,
Paid via Ship to Shipped,
)
)
ZIO.scoped {
for
fsm <- orderMachine.start(Pending)
_ <- fsm.send(Pay)
_ <- fsm.send(Ship)
state <- fsm.currentState
yield state
}.asDoc
}ShippedNext: Core Concepts for states, events, and hierarchy, or Testing for how DocSpecs assert.