trustfall icon indicating copy to clipboard operation
trustfall copied to clipboard

Think of optimization api implementation helper

Open u9g opened this issue 1 year ago • 0 comments

Based on this pr: https://github.com/obi1kenobi/trustfall/pull/339 it's super easy to implement one case of CandidateValue and forget about the rest, so a helper for implementing the Single/Multiple cases might be helpful.

An idea for api design:

make_iterator_from(
    resolve_info, // scan for CandidateValue::Single / CandidateValue::Multiple
    "name" // statically required property
    |key| Box::new(std::iter::once(Vertex::MyVertex(collection.get(key)))), // single candidate
    |keys| Box::new(keys.map(|key| Vertex::MyVertex(collection.get(key)))), // multiple candidates
    || Box::new(collection.values().map(|value| Vertex::MyVertex(value)))
)

Although maybe we can skip the ceremony and instead just have the programmer give us a way to lookup the key in the collection or transform the key into a vertex and implement the first two fn's ourselves

Once this is resolved, it can be added to stubgen.

u9g avatar Jul 07 '23 05:07 u9g