src/relock/relock.bend
ezx@1.11.0.0 · 83 lines · 10 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13import Base
14import ezx@1.11.0.0/src/lock/plan.bend as P
15import ezx@1.11.0.0/src/lock/world.bend as W
16
17
18def toml() -> String:
19 "ez.toml"
20
21
22def ledger.of(wrote: P.Wrote, was: Maybe<&2, String>) -> Maybe<&2, String>:
23 match wrote:
24 case P.Kept{}:
25 was
26 case P.Put{text}:
27 Some{text}
28
29
30def ledger(pl: P.Plan, was: Maybe<&2, String>) -> Maybe<&2, String>:
31 ledger.of(P.put.plan(pl, toml()), was)
32
33
34
35def world(+here: String, ledger: Maybe<&2, String>, listing: W.Listing, rs: List<&2, W.Reply>) -> W.World:
36 W.World{W.Args{False{}, "", here}, ledger, listing, rs, []}
37
38
39def outcome(pl: P.Plan) -> P.Outcome:
40 P.Plan{_es, o} = pl
41 o
42
43
44def refuses(pl: P.Plan) -> Bool:
45 P.Plan{_es, o} = pl
46 match o:
47 case P.Success{}:
48 False{}
49 case P.Refused{_why}:
50 True{}
51
52
53
54
55def join.lock(lock: P.Plan, +edit: P.Plan, notes: List<&2, P.Effect>, +tail: String) -> P.Plan:
56 P.Plan{es, outcome} = lock
57 match outcome:
58 case P.Success{}:
59 P.Plan{List.append(&2, P.Effect, P.effects(edit), List.append(&2, P.Effect, notes, es)),
60 P.Success{}}
61 case P.Refused{why}:
62 P.Plan{[], P.Refused{why ++ tail}}
63
64def join.edit(refused: Bool, +edit: P.Plan, lock: P.Plan, notes: List<&2, P.Effect>, +tail: String) -> P.Plan:
65 match refused:
66 case True{}:
67 P.Plan{[], P.Refused{P.why(outcome(edit))}}
68 case False{}:
69 join.lock(lock, edit, notes, tail)
70
71
72
73def join(+edit: P.Plan, lock: P.Plan, notes: List<&2, P.Effect>, +tail: String) -> P.Plan:
74 join.edit(refuses(edit), edit, lock, notes, tail)
75
76
77
78def asks(st: P.Step) -> List<&2, W.Ask>:
79 match st:
80 case P.Asking{as, _ups, ns}:
81 List.append(&2, W.Ask, as, ns)
82 case P.Run{_pl}:
83 []