def replace

bendvy-ecs-core@0.1.0.4 · ordinary_recovery_component.bend:32

import bendvy-ecs-core@0.1.0.4/ordinary_recovery_component.bend as OrdinaryRecoveryComponent
import Base
import bendvy-ecs-core@0.1.0.4/world.bend as W
import bendvy-ecs-core@0.1.0.4/column.bend as Col
import bendvy-ecs-core@0.1.0.4/owner_product.bend as Product
import bendvy-ecs-core@0.1.0.4/ordinary_component_binding.bend as B
import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_array_resource.bend as F
import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_component_capture.bend as Existing
import bendvy-ecs-core@0.1.0.4/recoverable_component.bend as RC
import bendvy-ecs-core@0.1.0.4/recoverable_component_family.bend as Family

32# Replace an optional component owner through the canonical binding.
33# Immediate refusal returns frame, incoming owner and error without adding
34# an inverse. Accepted records the displaced component receipt; commit returns
35# displaced owners, while rollback restores recorded state and recovers
36# replacements. Other World/capture owners are retained through the frame.
37def replace(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:C -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> C,~view:P -> P & V,~binding:B.Binding<S,C,Rest,P,V,Token,take,put,view>,~All:Type,~ReleasedRest:Type,~path:Product.Lens<All,List<RC.Record<S,P>>,ReleasedRest>,frame:F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>,handle:W.Handle<S>,incoming:Maybe<P>) -> Existing.ComponentAttempt<F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>,P>:
38  match frame:
39    case F.Frame{Product.Owner{world,capture},journal}:replaced(~S,~C,~R,~E,~Capture,~Rest,~P,~V,~Token,~take,~put,~view,~binding,~All,~ReleasedRest,~path,capture,journal,Family.replace(~S,~C,~R,~E,~Rest,~P,~V,~Token,~take,~put,~view,B.family(~S,~C,~Rest,~P,~V,~Token,~take,~put,~view,binding),world,handle,incoming))

Uses (15)

Used by (1)