Replies: 1 comment 3 replies
-
|
As it happens, this exact question was posed by @elbeno on a recent episode of ADSP. I don't think we have any particularly good way of handling this in Flux at the moment, other than either by stepping through manually with a cursor or using I'd like to offer a better solution if we can. I'm open to the idea of adding a function along the lines of void for_each_with_first_and_last(sequence, func1, func2, func3);i.e. you'd pass it three unary callbacks, and it would call An alternative approach might be to define an enum like enum class sequence_pos { front, middle, back }; and then introduce a sequence adaptor which yields a pair of for (auto [i, pos] : with_position(vec)) {
std::println("{} {}", i, to_string(pos));
}
// prints
// 1 front
// 2 middle
// 3 middle
// 4 middle
// 5 backI'm open to ideas, so if anyone has any thoughts or suggestions please let me know. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As per #244, what is the idiomatic way to handle the first, middle and last elements of a sequence differently?
My specific use case is handling the output of
flux::chunk(). I can process the middle elements with.drop(1).take(N - 2).for_each(), but am not sure this is best or how to handle the first and last elements.Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions