ordinary_recovery_resource.bend
bendvy-ecs-core@0.1.0.4 · 52 lines · 9 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
11import bendvy-ecs-core@0.1.0.4/world_resource_owner.bend as WR
12import bendvy-ecs-core@0.1.0.4/ordinary_schema.bend as Schema
13
14
15
16
17def Ops(~S:Data,~P:Type,~identity:Schema.Resource<S,Array<P>>,H:Type) -> Type:F.Write<S,P,identity,H>
18
19
20def target(~S:Data,~C:Type,~E:Data,~Capture:Type,~P:Type) -> Product.Lens<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,Array<P>,Capture & WR.Rest<S,C,Array<P>,E>>:
21 Product.compose(~Product.Owner<W.World<S,C,Array<P>,E>,Capture>,~W.World<S,C,Array<P>,E>,~Capture,~Array<P>,~WR.Rest<S,C,Array<P>,E>,~Product.lens(~W.World<S,C,Array<P>,E>,~Capture,~Product.Left{}),~WR.lens(~S,~C,~Array<P>,~E))
22def empty(~Capture:Type,~P:Type,unit:Unit) -> List<A.Record<P>>:[]
23def replaced(~S:Data,~C:Type,~E:Data,~Capture:Type,~P:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<P>>,Rest>,result:Product.Owner<W.World<S,C,Array<P>,E>,Capture> & List<Journal.Action(~Product.Owner<W.World<S,C,Array<P>,E>,Capture>,~All)>) -> F.Frame<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All>:
24 match result:
25 case (state,journal):F.Frame{state,journal}
26
27
28
29
30def replace(~S:Data,~C:Type,~E:Data,~Capture:Type,~P:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<P>>,Rest>,frame:F.Frame<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All>,incoming:Array<P>) -> F.Frame<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All>:
31 match frame:
32 case F.Frame{state,journal}:replaced(~S,~C,~E,~Capture,~P,~All,~Rest,~path,AO.replace(~Product.Owner<W.World<S,C,Array<P>,E>,Capture>,~P,~(Capture & WR.Rest<S,C,Array<P>,E>),~target(~S,~C,~E,~Capture,~P),~All,~Rest,~path,state,journal,incoming))
33def swapped(~S:Data,~C:Type,~E:Data,~Capture:Type,~P:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<P>>,Rest>,result:AO.Attempt<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All,P>) -> F.Attempt<F.Frame<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All>,P>:
34 match result:
35 case AO.Applied{state,journal}:F.Applied{F.Frame{state,journal}}
36 case AO.Refused{state,journal,incoming}:F.Refused{F.Frame{state,journal},incoming}
37
38
39
40def swap(~S:Data,~C:Type,~E:Data,~Capture:Type,~P:Type,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<P>>,Rest>,frame:F.Frame<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All>,index:U32,incoming:P) -> F.Attempt<F.Frame<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All>,P>:
41 match frame:
42 case F.Frame{state,journal}:swapped(~S,~C,~E,~Capture,~P,~All,~Rest,~path,AO.swap(~Product.Owner<W.World<S,C,Array<P>,E>,Capture>,~P,~(Capture & WR.Rest<S,C,Array<P>,E>),~target(~S,~C,~E,~Capture,~P),~All,~Rest,~path,state,journal,index,incoming))
43
44
45def grant(~S:Data,~C:Type,~E:Data,~Capture:Type,~P:Type,~identity:Schema.Resource<S,Array<P>>,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<P>>,Rest>,unit:Unit) -> F.Write<S,P,identity,F.Frame<Product.Owner<W.World<S,C,Array<P>,E>,Capture>,All>>:
46 F.Write{replace(~S,~C,~E,~Capture,~P,~All,~Rest,~path),swap(~S,~C,~E,~Capture,~P,~All,~Rest,~path)}
47
48
49
50
51def declaration(~S:Data,~C:Type,~E:Data,~Capture:Type,~P:Type,~identity:Schema.Resource<S,Array<P>>) -> D.Declaration<S,Product.Owner<W.World<S,C,Array<P>,E>,Capture>,List<A.Record<P>>,Ops(~S,~P,~identity),grant(~S,~C,~E,~Capture,~P,~identity)>:
52 D.Described{empty(~Capture,~P),[Schema.resource_key(~S,~Array<P>,identity)],Use.known([Use.Use{Use.Resource{Schema.resource_key(~S,~Array<P>,identity)},Use.Write{}}])}