the whole framework on one page. print it out.
value | op | op | (collect OR run)
# every ZefOp works eager or lazy
trim('abcd', 'a') β‘ 'abcd' | trim('a') | collect
# data-flow arg always goes first
op(args, x) β‘ x | op(args)
# pipelines are values
my_chain = map(add(1)) | filter(Z > 3)
[1, 2, 3] | my_chain | collect
| op | use |
|---|---|
collect | execute pure pipeline |
run | execute an effect |
map(f) / apply(f) | transform each / one |
filter(p) | keep matching |
reduce(f) / scan(f) | fold / fold-with-history |
first / last / nth(i) | pick one |
length / unique / sort | collection ops |
group_by(k) | bucket |
sliding(n) / window_reduce(f, n) | moving windows |
match(cases) | pattern dispatch |
rearrange(tmpl) | reshape by template |
F.x / Fs.x | single / set projection |
parse_json / to_json | JSON I/O |
log | print & pass through |
| prefix | meaning |
|---|---|
π- | platonic UID (global, 20 hex) |
π§- | snapshot UID (specific DB state) |
πΈοΈ- | graph-local ref |
πΏ- | content-hashed value |
ET.Person(name='Alice') # single field
ET.Person(likes_={'π', 'πΊ'}) # multi (set)
ET.Person(visited_=[c1, c2]) # multi (ordered list)
ET.Person('π-abc...', name='Bob') # update/create by UID
ET.Person(3, name='Bob') # update by local index
name='Bob' # replace single value
likes_={'a', 'b'} # replace set
likes_= this + {'c'} # append
likes_= this - {'a'} # remove
likes_={} # clear set
42 | is_a(Int) # True
Int | String # union
Int & (Z > 18) # intersection / refinement
~String # complement
Array[Int | Float] # container refinement
ET.Person['age': Int & (Z > 18), ...] # entity refinement
eff = FX.Whatever(field=1) # build (nothing happens)
eff | run # fire it
eff.field # inspect
# partial build + insert_into
pub = FX.Publish(target=topic)
'hi' | insert_into(pub, 'content') | run
topic = ET.Topic('π-...20hex...')
@zef_function
def h(msg, state):
return [[/* effects */], new_state]
actor = FX.StartActor(input=topic, initial_state=0, handler=h) | run
FX.Publish(target=topic, content='hi') | run
FX.QueryActorState(actor=actor) | run
FX.StopActor(actor=actor) | run
FX.StartHTTPServer(
routes={
'/': 'hi',
'/api': ET.JSON(content={'ok': True}),
('POST', '/x'): my_handler,
'/ws': ET.WebSocket(clients_subscribe_to=[t], clients_push_into_=[t]),
},
port=8000,
) | run
db = FX.CreateDB(type=DictDatabase, persistence='vault') | run
FX.UpdateDB(db=db, insert={'k': v}) | run
v = FX.QueryDB(db=db, get='k') | run
# shorthand
db['k'] = v
v = db['k']
s = FX.CreateSignal(value=0, history=100) | run
FX.UpdateSignal(signal=s, transform=add(1)) | run
FX.ReadSignal(signal=s) | run
FX.ReadSignalHistory(signal=s) | run
t = FX.StartTimer(interval=1, target=topic, content='tick') | run
# or interval='hourly' / 'daily' / ...
FX.StopTimer(timer=t) | run
V = z.Forward
V = Int | String | Sequence['[', [V], ']']
input_str | parse2(V) | collect
| collect or | runfield replaces, field_ replaces set, field_=this + ... appends[effects_list, new_state] exactlyUpdateSignal transforms must be PUREcollect inside FX.SubscribeFX(op=...).upper(), isinstance(x, int))jq zefops.json# find a ZefOp by name / fuzzy
jq '.[] | select(.name == "parse_json")' zefops.json
jq -r '.[].name' zefops.json | grep -iE 'json|field'
# get blurb + signature + example for anything matching
jq '.[] | select(.name | test("json"; "i")) | {name, blurb, signature_, minimal_code_examples}' zefops.json
notes/Overview.md β index of ALL notesnotes/Using Zef from Python - A Practical Guide.md β canonical referencenotes/Actors - Hands-On Guide.md β deeper actor patternsnotes/HTTP Servers.md β full HTTP docsnotes/Zef Effects System (Zef FX).md β every FXzefops.json β machine-readable catalog
β¨ you've reached the end β¨
now go build something.
if this zine helped you, write your own. the best way to learn zef is to
explain it to someone else.
πΏ happy piping! πΏ