def swap

bendvy-ecs-core@0.1.0.4 · ordinary_recovery_resource_field.bend:41

import bendvy-ecs-core@0.1.0.4/ordinary_recovery_resource_field.bend as OrdinaryRecoveryResourceField
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

41# Advanced bounds-checked element replacement consuming P. Applied journals old P;
42# Refused returns actual incoming P with state/journal preserved when index is out
43# of bounds. Recovery follows shared journal order; unlike raw Array access this
44# does not wrap an invalid index into another slot.
45def swap(~S:Data,~C:Type,~E:Data,~Capture:Type,~R:Type,~P:Type,~FieldRest:Type,~fieldLens:Product.Lens<R,Array<P>,FieldRest>,~All:Type,~Rest:Type,~path:Product.Lens<All,List<A.Record<P>>,Rest>,frame:F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>,index:U32,incoming:P) -> F.Attempt<F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>,P>:
46  match frame:
47    case F.Frame{state,journal}:swapped(~S,~C,~E,~Capture,~R,~P,~FieldRest,~fieldLens,~All,~Rest,~path,AO.swap(~Product.Owner<W.World<S,C,R,E>,Capture>,~P,~((Capture & WR.Rest<S,C,R,E>) & FieldRest),~target(~S,~C,~E,~Capture,~R,~P,~FieldRest,~fieldLens),~All,~Rest,~path,state,journal,index,incoming))

Uses (14)

Used by (1)