ordinary_app_records.bend
bendvy-ecs-core@0.1.0.1 · 32 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.1/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.
6type Record<S:Data,Token:Type> is Type:
7 Record{token:Token,fields:Stored.Fields<S>}
8# Return the record owner together with its one detached Fields entry.
9# Does not invoke the registration, advance its cursor or read payloads.
10def observed(~S:Data,~Token:Type,record:Record<S,Token>) -> Record<S,Token> & List<&2,Stored.Fields<S>>:
11 match record:
12 case Record{token,+fields}:(Record{token,fields},[fields])
13def second(~S:Data,~Left:Type,~Right:Type,left:Left,before:List<&2,Stored.Fields<S>>,result:Right & List<&2,Stored.Fields<S>>) -> (Left & Right) & List<&2,Stored.Fields<S>>:
14 match result:
15 case (right,after):((left,right),List.append(&2,Stored.Fields<S>,before,after))
16def first(~S:Data,~Left:Type,~Right:Type,rightFold:Right -> Right & List<&2,Stored.Fields<S>>,right:Right,result:Left & List<&2,Stored.Fields<S>>) -> (Left & Right) & List<&2,Stored.Fields<S>>:
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.
22def pair(~S:Data,~Left:Type,~Right:Type,leftFold:Left -> Left & List<&2,Stored.Fields<S>>,rightFold:Right -> Right & List<&2,Stored.Fields<S>>,owners:Left & Right) -> (Left & Right) & List<&2,Stored.Fields<S>>:
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.
27def empty(~S:Data,unit:Unit) -> Unit & List<&2,Stored.Fields<S>>:
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.
31def fold_pair(~S:Data,~Left:Type,~Right:Type,~left:Left -> Left & List<&2,Stored.Fields<S>>,~right:Right -> Right & List<&2,Stored.Fields<S>>,owners:Left & Right) -> (Left & Right) & List<&2,Stored.Fields<S>>:
32 pair(~S,~Left,~Right,left,right,owners)