restore_graph_mapping.bend source
restore_graph_mapping.bend on the hub · documented module
import Baseimport ./entity_key.bend as Keyimport ./world.bend as Wimport ./restore_data.bend as Basicimport ./relation_types.bend as Gimport ./relation_graph.bend as Graphtype Mapped<S:Data> is Data: Mapped{graph:G.Graph<S>} MissingBinding{saved:Key.Key}def target(~S:Data,descriptor:G.Descriptor<S>,source:W.Handle<S>,saved:Key.Key,result:Maybe<&2,W.Handle<S>>,graph:G.Graph<S>,next:G.Graph<S> -> Mapped<S>) -> Mapped<S>: match source result graph: case _ None{} _:MissingBinding{saved} case W.Handle{_,source} Some{W.Handle{_,target}} G.Graph{edges,inverses}:next(Graph.updated(~S,False{},edges,inverses,descriptor,source,target))def source(~S:Data,descriptor:G.Descriptor<S>,saved:Key.Key,+other:Key.Key,+bindings:List<&2,Basic.Binding<S>>,result:Maybe<&2,W.Handle<S>>,graph:G.Graph<S>,next:G.Graph<S> -> Mapped<S>) -> Mapped<S>: match result: case None{}:MissingBinding{saved} case Some{handle}:target(~S,descriptor,handle,other,Basic.lookup(~S,other,bindings),graph,next)def edges(~S:Data,values:List<&2,G.Edge<S>>,+bindings:List<&2,Basic.Binding<S>>,graph:G.Graph<S>) -> Mapped<S>: match values: case []:Mapped{graph} case G.Edge{descriptor,+saved,other} <> rest:source(~S,descriptor,saved,other,bindings,Basic.lookup(~S,saved,bindings),graph,graph => edges(~S,rest,bindings,graph))def remap(~S:Data,graph:G.Graph<S>,bindings:List<&2,Basic.Binding<S>>) -> Mapped<S>: match graph: case G.Graph{values,_}:edges(~S,values,bindings,G.Graph{[],[]})