1 import Base 2 import ./world.bend as W 3 4 # Remove exact registration identity, preserving every other system instance. 5 # IDs are monotonic and are not recycled by disposal. 6 def retained(keep: Bool,meta: W.RegistrationMeta,rest: List<&2,W.RegistrationMeta>) -> List<&2,W.RegistrationMeta>: 7 match keep: 8 case True{}: meta <> rest 9 case False{}: rest 10 11 def without(registrations: List<&2,W.RegistrationMeta>,+id: U32,+name: String,+access: List<&2,String>) -> List<&2,W.RegistrationMeta>: 12 match registrations: 13 case []: [] 14 case +meta <> rest: retained(Bool.not(W.registration_meta_matches(meta,id,name,access)),meta,without(rest,id,name,access)) 15 16 def remove_checked(~S: Data,~Store: Type,~R: Type,~E: Data,allowed: Bool,world: W.World,+id: U32,+name: String,+access: List<&2,String>) -> W.World & Bool: 17 match allowed world: 18 case False{} world: (world,False{}) 19 case True{} W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock}: (W.World{namespace,allocator,store,resource,events,pending,without(registrations,id,name,access),nextSystemId,clock},True{}) 20 21 def remove(~S: Data,~Store: Type,~R: Type,~E: Data,world: W.World,namespace: U32,+id: U32,+name: String,+access: List<&2,String>) -> W.World & Bool: 22 match world: 23 case W.World{+actual,allocator,store,resource,events,pending,+registrations,nextSystemId,clock}: remove_checked(~S,~Store,~R,~E,Bool.and(U32.is_eq(namespace,actual),W.registration_list_matches(registrations,id,name,access)),W.World{actual,allocator,store,resource,events,pending,registrations,nextSystemId,clock},id,name,access)