1 import Base 2 import ./ordinary_app_registration_fields.bend as Stored 3 # Advanced application carrier pairing actual affine registration Token 4 # with its detached Fields. Fields alone do not replace registration authority; 5 # keep token and metadata from the same registration together. 6 type Record is Type: 7 Record{token:Token,fields:Stored.Fields} 8 # Return the record owner together with its one detached Fields entry. 9 # Does not invoke the registration, advance its cursor or read payloads. 10 def observed(~S:Data,~Token:Type,record:Record) -> Record & List<&2,Stored.Fields>: 11 match record: 12 case Record{token,+fields}:(Record{token,fields},[fields]) 13 def second(~S:Data,~Left:Type,~Right:Type,left:Left,before:List<&2,Stored.Fields>,result:Right & List<&2,Stored.Fields>) -> (Left & Right) & List<&2,Stored.Fields>: 14 match result: 15 case (right,after):((left,right),List.append(&2,Stored.Fields,before,after)) 16 def first(~S:Data,~Left:Type,~Right:Type,rightFold:Right -> Right & List<&2,Stored.Fields>,right:Right,result:Left & List<&2,Stored.Fields>) -> (Left & Right) & List<&2,Stored.Fields>: 17 match result: 18 case (left,before):second(~S,~Left,~Right,left,before,rightFold(right)) 19 # Advanced metadata fold over heterogeneous owners in left/right order. 20 # Returns both owners and appended detached fields; supplied folds must 21 # preserve their owned registrations rather than fabricate authority. 22 def pair(~S:Data,~Left:Type,~Right:Type,leftFold:Left -> Left & List<&2,Stored.Fields>,rightFold:Right -> Right & List<&2,Stored.Fields>,owners:Left & Right) -> (Left & Right) & List<&2,Stored.Fields>: 23 match owners: 24 case (left,right):first(~S,~Left,~Right,rightFold,right,leftFold(left)) 25 # Unit-owner base metadata fold, returning the same Unit and no fields. 26 # Does not register a system or infer metadata from arbitrary owners. 27 def empty(~S:Data,unit:Unit) -> Unit & List<&2,Stored.Fields>: 28 (unit,[]) 29 # Closed advanced adapter composing two metadata folds with the same 30 # owner-threading and left/right order as pair; does not execute systems. 31 def fold_pair(~S:Data,~Left:Type,~Right:Type,~left:Left -> Left & List<&2,Stored.Fields>,~right:Right -> Right & List<&2,Stored.Fields>,owners:Left & Right) -> (Left & Right) & List<&2,Stored.Fields>: 32 pair(~S,~Left,~Right,left,right,owners)