src/remove/relock.bend
ezx@1.11.0.0 · 79 lines · 12 definitions
1
2
3
4
5
6
7
8
9
10
11
12import Base
13import ezx@1.11.0.0/src/remove/plan.bend as RP
14import ezx@1.11.0.0/src/lock/plan.bend as P
15import ezx@1.11.0.0/src/lock/world.bend as W
16import ezx@1.11.0.0/src/relock/relock.bend as R
17
18
19
20type World is Data:
21 World{remove: RP.World, here: String, listing: W.Listing, locks: List<&2, W.Reply>}
22
23
24def remove(world: World) -> RP.World:
25 World{r, _here, _listing, _locks} = world
26 r
27
28
29def ledger.was(rw: RP.World) -> Maybe<&2, String>:
30 RP.World{_n, l, _ig} = rw
31 l
32
33
34def lock.world(world: World) -> W.World:
35 World{+r, +here, listing, locks} = world
36 R.world(here, R.ledger(RP.plan(r), ledger.was(r)), listing, locks)
37
38
39def lock(world: World) -> P.Plan:
40 P.plan(lock.world(world))
41
42
43def tail() -> String:
44 "\nez: ez remove wrote nothing, since it writes ez.toml and ez.lock.toml together;" ++
45 " a .bend file that still imports what it removes has to stop first"
46
47
48def plan(world: World) -> P.Plan:
49 World{+r, +here, +listing, +locks} = world
50 R.join(RP.plan(r), lock(World{r, here, listing, locks}), [], tail())
51
52
53def refuses(world: World) -> Bool:
54 R.refuses(plan(world))
55
56
57type Next is Data:
58 AskLock{asks: List<&2, W.Ask>}
59 Planned{plan: P.Plan}
60
61
62def next.lock(st: P.Step, +world: World) -> Next:
63 match st:
64 case P.Asking{as, ups, ns}:
65 AskLock{R.asks(P.Asking{as, ups, ns})}
66 case P.Run{_pl}:
67 Planned{plan(world)}
68
69
70def next.made(refused: Bool, +world: World) -> Next:
71 match refused:
72 case True{}:
73 Planned{plan(world)}
74 case False{}:
75 next.lock(P.step(lock.world(world)), world)
76
77
78def next(+world: World) -> Next:
79 next.made(R.refuses(RP.plan(remove(world))), world)