def observe
import bendtorch-core@0.1.0.0/src/storage/model.bend as Modelimport Base
56def observe(-T: Data, d: Nat, array: Array<T>, path: Path(d)) -> Maybe<&2, T>:
57 match d array:
58 case 0n ALeaf{x}:
59 Some{x}
60 case 0n ANode{xs, ys}:
61 None{}
62 case 1n+p ALeaf{x}:
63 None{}
64 case 1n+p ANode{xs, ys}:
65 Step{bit, rest} = path
66 match bit:
67 case False{}:
68 observe(T, p, xs, rest)
69 case True{}:
70 observe(T, p, ys, rest)