recoverable_owner.bend

bendvy-ecs-core@0.1.0.0 · 13 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.0/owner_product.bend as Product
3# Only canonical product exchanges create these inverses. No body-provided inverse.
4def replaced(~State:Type,~P:Type,~Rest:Type,~lens:Product.Lens<State,P,Rest>,replacement:P,taken:Rest & P) -> State & P:
5  match taken:
6    case (rest,old):(Product.put_field(~State,~P,~Rest,lens)(rest,replacement),old)
7def exchange(~State:Type,~P:Type,~Rest:Type,~lens:Product.Lens<State,P,Rest>,state:State,replacement:P) -> State & P:
8  replaced(~State,~P,~Rest,~lens,replacement,Product.get_field(~State,~P,~Rest,lens)(state))
9def appended(~Recovery:Type,~P:Type,~Rest:Type,~lens:Product.Lens<Recovery,List<P>,Rest>,value:P,taken:Rest & List<P>) -> Recovery:
10  match taken:
11    case (rest,values):Product.put_field(~Recovery,~List<P>,~Rest,lens)(rest,value <> values)
12def append(~Recovery:Type,~P:Type,~Rest:Type,~lens:Product.Lens<Recovery,List<P>,Rest>,recovery:Recovery,value:P) -> Recovery:
13  appended(~Recovery,~P,~Rest,~lens,value,Product.get_field(~Recovery,~List<P>,~Rest,lens)(recovery))