flux icon indicating copy to clipboard operation
flux copied to clipboard

Automatically unpack tuples in map/filter etc

Open tcbrindle opened this issue 1 year ago • 0 comments

Today's Advent of Code was a reminder that even with flux::unpack, working with sequences which yield tuples can be really ugly:

screenshot

To avoid this, we could automatically unpack tuples in sequence adaptors where possible, allowing users to write something like

auto seq = flux::zip(get_vector(), get_string())
                  .map([](int i, char c) { ... });

that is, without needing to wrap the lambda in flux::unpack.

I think the best way to do this is to add our own flux::invoke(f, args...) which:

  • First tries std::invoke(f, args...)
  • If that fails, and if the args... pack has exactly one element, tries again with std::invoke(unpack(f), args...)

We'd also need corresponding versions of invoke_result_t and the invocable concept.

If we make this change, it would also be worth looking at the codegen of e.g cartesian_product_map and zip_map vs cartesian_product.map and zip.map to see whether it's worth keeping the former around.

tcbrindle avatar Dec 04 '24 17:12 tcbrindle