Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is uniq a sink? #30

Open
Kijewski opened this issue Nov 19, 2019 · 1 comment
Open

Why is uniq a sink? #30

Kijewski opened this issue Nov 19, 2019 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers version-2.1 Features that are destined for version 2.1

Comments

@Kijewski
Copy link
Contributor

I would expect it to work like

RX_OPTIONAL<output_type> last_value;

uniq(…) {
    last_value.emplace(input.get());
    input.next();
}

constexpr void next() {
    while (!input.at_end()) {
        auto&& next_value = input.get();
        input.next();
        if (!eq(*last_value, next_value)) {
            last_value.emplace(std::forward<decltype(next_value)>(next_value));
            return;
        }
    }
    last_value.reset();
}

constexpr output_type get() const {
    return last_value;
}
@simonask
Copy link
Owner

It's a sink because the most common use case for it is sort() | uniq(), and if it was a normal input range, that particular construct would allocate temporary storage.

However, we do have the option to overload operator() for cases when its input is another sink (in which case calling std::unique on the output is the right thing), and when it is part of a chain of input ranges. Might be a nice addition for version 2.1. :-)

@simonask simonask added good first issue Good for newcomers enhancement New feature or request version-2.1 Features that are destined for version 2.1 labels Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers version-2.1 Features that are destined for version 2.1
Projects
None yet
Development

No branches or pull requests

2 participants