Getting Started
-
Write a behaviour
A behaviour is a Nix function
msg → attrset. No imports, no base class:counter =count: msg:if msg == "inc" then{ reply = count + 1; next-behaviour = counter (count + 1); }else if msg == "get" then{ reply = count; }else{ };reply— value placed in the outbox.next-behaviour— behaviour for the next message. Returning{ }silently drops the message. -
Wrap it in an actor
actortakes an initial behaviour and returns a cycle-c — a function{ inbox } → { outbox, states }:inherit (dnzl) actor;counter-c = actor (counter 0); -
Feed it a stream
stbuilds a stream from its arguments:inherit (dnzl.ned) st;result = counter-c { inbox = st "inc" "inc" "get"; };result.outbox.toList# → [ 1 2 2 ] -
Use the helpers
replyandbecomeare sugar for constructing the response attrset:inherit (dnzl) actor reply become;counter =count: msg:if msg == "inc" thenreply (count + 1) // become (counter (count + 1))else if msg == "get" thenreply countelse{ };reply.right/reply.lefttag values as Either — enables stream splitting:counter =count: msg:if msg == "inc" then reply.right (count + 1) // become (counter (count + 1))else if msg == "get" then reply.right countelse { };counter-c = actor (counter 0);result = counter-c { inbox = st "inc" "inc" "get"; };result.outbox.toList# → [ { right = 1; } { right = 2; } { right = 2; } ]
Stateless actors with map-c
Section titled “Stateless actors with map-c”For pure stream transforms with no state, map-c is more direct than actor:
inherit (dnzl.ned) st map-c;
double-c = map-c (n: n * 2); # ST → ST, no inbox/outbox wrapper
(double-c (st 1 2 3)).toList# → [ 2 4 6 ]map-c f returns a stream transformer. Call it directly on a stream, not as { inbox = ... }.
Minimal flake setup
Section titled “Minimal flake setup”{ inputs.dnzl.url = "github:denful/dnzl"; outputs = { dnzl, ... }: let d = dnzl.lib; in { # d.actor, d.reply, d.become, d.send, d.merge # d.ned.st, d.ned.map-c, d.ned.when-c, d.ned.run, d.ned.static-d };}What’s next
Section titled “What’s next”- Actors and Streams —
actor,scanl,STfunctor in depth - Reply and Become — stateful actors, Either routing
- Building Pipelines — multi-actor wiring