~/bend-docscommunity

execution_query_matches.bend source

execution_query_matches.bend on the hub · documented module

import Baseimport ./lifecycle.bend as Lifeimport ./execution_query_domain.bend as Dtype Recipe is Data:  Read{domain:D.Domain}  Write{domain:D.Domain}  Both{left:Recipe,right:Recipe}type Presence is Data:  Optional{}  Required{}  With{}  Without{}type Row<-V:Data> is Data:  Row{offset:U32,view:Maybe<&2,V>}  StampedRow{offset:U32,view:Maybe<&2,V>,stamp:Life.Stamp}# Raw Row carries unknown lifecycle metadata; canonical caches use StampedRow.def row_offset(-V:Data,row:Row<V>) -> U32:  match row:    case Row{offset,_}:offset    case StampedRow{offset,_,_}:offsetdef row_view(-V:Data,row:Row<V>) -> Maybe<&2,V>:  match row:    case Row{_,view}:view    case StampedRow{_,view,_}:viewdef row_stamp(-V:Data,row:Row<V>) -> Life.Stamp:  match row:    case Row{_,_}:Life.Stamp{None{},None{}}    case StampedRow{_,None{},_}:Life.Stamp{None{},None{}}    case StampedRow{_,Some{_},stamp}:stamptype Single<-V:Data> is Data:  NoMatch{}  One{row:Row<V>}  Multiple{}def present(-V:Data,value:Maybe<&2,V>) -> Bool:  match value:    case None{}:False{}    case Some{_}:True{}def membership(-V:Data,presence:Presence,value:Maybe<&2,V>) -> Bool:  match presence:    case Optional{}:True{}    case Required{}:present(V,value)    case With{}:present(V,value)    case Without{}:Bool.not(present(V,value))def selected_row(-V:Data,offset:U32,view:Maybe<&2,V>,rows:List<&2,Row<V>>,matched:Bool) -> List<&2,Row<V>>:  match matched:    case False{}:rows    case True{}:Row{offset,view} <> rowsdef single(-V:Data,rows:List<&2,Row<V>>) -> Single<V>:  match rows:    case []:NoMatch{}    case row <> []:One{row}    case _ <> _ <> _:Multiple{}def count(-V:Data,rows:List<&2,Row<V>>) -> U32:  match rows:    case []:0    case _ <> rest:U32.add(1,count(V,rest))def inventory_valid(result:D.Validation) -> Bool:  match result:    case D.Valid{}:True{}    case _:False{}def validate_recipe(+capacity:U32,recipe:Recipe) -> Bool:  match recipe:    case Read{domain}:inventory_valid(D.validate(capacity,domain))    case Write{domain}:inventory_valid(D.validate(capacity,domain))    case Both{left,right}:Bool.and(validate_recipe(capacity,left),validate_recipe(capacity,right))