flyt

06 — Entities

State with a key, and one pure transition.

Every change is a command through one pure apply. A refused command changes nothing.

carts/entities.flyt
entity cart {
  key: CartId
  state: Cart
  command: Command
  reject: Rejection

  apply(state, command) {
    match state {
      None -> match command {
        AddLine { customer, line, currency, at } ->
          Applied { state: rules.opened(customer, line, currency, at) }
        RemoveLine { .. } -> Rejected { reason: NoCart }
      }
      Some(cart) -> match rules.step(cart, command) {
        Next { cart: next } -> Applied { state: next }
        Refuse { reason } -> Rejected { reason }
      }
    }
  }
}
Send a command to carts/c_81
Commandnothing sent yet
apply(state, command)pure, inside your transaction
Outcome—
carts/c_81

No row yet