declared_family.bend
bendvy-ecs-core@0.1.0.0 · 24 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.0/ordinary_declaration.bend as Identity
3import bendvy-ecs-core@0.1.0.0/persistence_declaration.bend as Decl
4import bendvy-ecs-core@0.1.0.0/snapshot_leaf.bend as Leaf
5import bendvy-ecs-core@0.1.0.0/decode_data.bend as D
6import bendvy-ecs-core@0.1.0.0/component.bend as Cmp
7import bendvy-ecs-core@0.1.0.0/column.bend as Col
8import bendvy-ecs-core@0.1.0.0/schema_fragments.bend as SF
9
10# Closed trusted schema lenses, as in existing component.Family. The retained
11# recipe becomes part of Family's Rest and survives ordinary column operations.
12def split(~S:Data,~P:Type,~Rest:Type,~identity:Identity.Declaration<S,P>,~save:P -> P & D.Raw,observed:Rest & Leaf.Component<S,P,identity,save>) -> (Rest & Decl.Constructed<S,P,identity,save>) & Col.Column<S,P>:
13 match observed:
14 case (rest,Leaf.Component{column,declaration}):((rest,declaration),column)
15def take_column(~S:Data,~P:Type,~Store:Type,~Rest:Type,~identity:Identity.Declaration<S,P>,~save:P -> P & D.Raw,~take:Store -> Rest & Leaf.Component<S,P,identity,save>,owner:Store) -> (Rest & Decl.Constructed<S,P,identity,save>) & Col.Column<S,P>:
16 split(~S,~P,~Rest,~identity,~save,take(owner))
17def put_column(~S:Data,~P:Type,~Store:Type,~Rest:Type,~identity:Identity.Declaration<S,P>,~save:P -> P & D.Raw,~put:Rest -> Leaf.Component<S,P,identity,save> -> Store,rest:Rest & Decl.Constructed<S,P,identity,save>,column:Col.Column<S,P>) -> Store:
18 match rest:
19 case (rest,declaration):put(rest,Leaf.Component{column,declaration})
20def family(~S:Data,~P:Type,~Store:Type,~Rest:Type,~V:Data,~Token:Data,~identity:Identity.Declaration<S,P>,~save:P -> P & D.Raw,~view:P -> P & V,~take:Store -> Rest & Leaf.Component<S,P,identity,save>,~put:Rest -> Leaf.Component<S,P,identity,save> -> Store) -> Cmp.Family<S,Store,Rest & Decl.Constructed<S,P,identity,save>,P,V,Token,take_column(~S,~P,~Store,~Rest,~identity,~save,~take),put_column(~S,~P,~Store,~Rest,~identity,~save,~put),view>:
21 Cmp.Family{Identity.key(~S,~P,identity)}
22def descriptor(~S:Data,~P:Type,~Token:Data,~identity:Identity.Declaration<S,P>) -> SF.Descriptor<S,Token,P>:
23 +key=Identity.key(~S,~P,identity)
24 SF.Descriptor{SF.Component{},key,key}