def swap

bendvy-ecs-core@0.1.0.4 · ordinary_recovery_resource.bend:37

import bendvy-ecs-core@0.1.0.4/ordinary_recovery_resource.bend as OrdinaryRecoveryResource
import Base
import bendvy-ecs-core@0.1.0.4/world.bend as W
import bendvy-ecs-core@0.1.0.4/owner_product.bend as Product
import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_array_resource.bend as F
import bendvy-ecs-core@0.1.0.4/recoverable_array.bend as A
import bendvy-ecs-core@0.1.0.4/recoverable_array_owner.bend as AO
import bendvy-ecs-core@0.1.0.4/world_resource_owner.bend as WR

37# Attempt one Array<P> resource element swap. Out-of-bounds returns Refused
38# with incoming P and unchanged journal; success records the displaced owner.
39# Receipt recovery follows the enclosing commit/rollback, not immediate copying.
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))

Uses (14)

Used by (1)