ordinary_recovery_capture.bend
bendvy-ecs-core@0.1.0.4 · 45 lines · 8 definitions
1import Base
2import bendvy-ecs-core@0.1.0.4/recovery_use.bend as Use
3import bendvy-ecs-core@0.1.0.4/world.bend as W
4import bendvy-ecs-core@0.1.0.4/owner_product.bend as Product
5import bendvy-ecs-core@0.1.0.4/ordinary_recovery_declaration.bend as D
6import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_array_resource.bend as F
7import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_component_capture.bend as Existing
8import bendvy-ecs-core@0.1.0.4/recoverable_array.bend as A
9import bendvy-ecs-core@0.1.0.4/recoverable_array_owner.bend as AO
10import bendvy-ecs-core@0.1.0.4/recovery_journal.bend as Journal
11
12
13
14
15def Ops(~Q:Type,H:Type) -> Type:Existing.CaptureWrite<Q,H>
16def empty(~Q:Type,unit:Unit) -> List<A.Record<Q>>:[]
17def replaced(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<Q>>,Rest>,result:Product.Owner<W.World<S,C,R,E>,Array<Q>> & List<Journal.Action(~Product.Owner<W.World<S,C,R,E>,Array<Q>>,~All)>) -> F.Frame<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All>:
18 match result:
19 case (state,journal):F.Frame{state,journal}
20
21
22
23
24def replace(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<Q>>,Rest>,frame:F.Frame<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All>,incoming:Array<Q>) -> F.Frame<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All>:
25 match frame:
26 case F.Frame{state,journal}:replaced(~S,~C,~R,~E,~Q,~All,~Rest,~path,AO.replace(~Product.Owner<W.World<S,C,R,E>,Array<Q>>,~Q,~W.World<S,C,R,E>,~Product.lens(~W.World<S,C,R,E>,~Array<Q>,~Product.Right{}),~All,~Rest,~path,state,journal,incoming))
27def swapped(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<Q>>,Rest>,result:AO.Attempt<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All,Q>) -> F.Attempt<F.Frame<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All>,Q>:
28 match result:
29 case AO.Applied{state,journal}:F.Applied{F.Frame{state,journal}}
30 case AO.Refused{state,journal,incoming}:F.Refused{F.Frame{state,journal},incoming}
31
32
33
34def swap(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<Q>>,Rest>,frame:F.Frame<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All>,index:U32,incoming:Q) -> F.Attempt<F.Frame<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All>,Q>:
35 match frame:
36 case F.Frame{state,journal}:swapped(~S,~C,~R,~E,~Q,~All,~Rest,~path,AO.swap(~Product.Owner<W.World<S,C,R,E>,Array<Q>>,~Q,~W.World<S,C,R,E>,~Product.lens(~W.World<S,C,R,E>,~Array<Q>,~Product.Right{}),~All,~Rest,~path,state,journal,index,incoming))
37
38
39
40def grant(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<Q>>,Rest>,unit:Unit) -> Existing.CaptureWrite<Q,F.Frame<Product.Owner<W.World<S,C,R,E>,Array<Q>>,All>>:Existing.CaptureWrite{replace(~S,~C,~R,~E,~Q,~All,~Rest,~path),swap(~S,~C,~R,~E,~Q,~All,~Rest,~path)}
41
42
43
44
45def declaration(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Type) -> D.Declaration<S,Product.Owner<W.World<S,C,R,E>,Array<Q>>,List<A.Record<Q>>,Ops(~Q),grant(~S,~C,~R,~E,~Q)>:D.Described{empty(~Q),[],Use.known([Use.Use{Use.Capture{},Use.Write{}}])}