Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/rpp/rpp/operators/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace rpp::operators
auto take_until(TObservable&& until_observable);

template<std::invocable<const std::exception_ptr&> OnError = rpp::utils::empty_function_t<std::exception_ptr>>
requires utils::is_not_template_callable<OnError>
auto tap(OnError&& on_error);

template<std::invocable<> OnCompleted = rpp::utils::empty_function_t<>>
Expand All @@ -169,6 +170,7 @@ namespace rpp::operators
template<typename OnNext = rpp::utils::empty_function_any_t,
std::invocable<const std::exception_ptr&> OnError = rpp::utils::empty_function_t<std::exception_ptr>,
std::invocable<> OnCompleted = rpp::utils::empty_function_t<>>
requires utils::is_not_template_callable<OnError>
auto tap(OnNext&& on_next = {},
OnError&& on_error = {},
OnCompleted&& on_completed = {});
Expand Down
2 changes: 2 additions & 0 deletions src/rpp/rpp/operators/tap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace rpp::operators
* @see https://reactivex.io/documentation/operators/do.html
*/
template<std::invocable<const std::exception_ptr&> OnError /* = rpp::utils::empty_function_t<std::exception_ptr> */>
requires utils::is_not_template_callable<OnError>
auto tap(OnError&& on_error)
{
using OnNext = rpp::utils::empty_function_any_t;
Expand Down Expand Up @@ -156,6 +157,7 @@ namespace rpp::operators
template<typename OnNext /* = rpp::utils::empty_function_any_t */,
std::invocable<const std::exception_ptr&> OnError /* = rpp::utils::empty_function_t<std::exception_ptr> */,
std::invocable<> OnCompleted /* = rpp::utils::empty_function_t<> */>
requires utils::is_not_template_callable<OnError>
auto tap(OnNext&& on_next /* = {} */,
OnError&& on_error /* = {} */,
OnCompleted&& on_completed /* = {} */)
Expand Down
14 changes: 14 additions & 0 deletions src/tests/rpp/test_tap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ TEMPLATE_TEST_CASE("tap observes emissions and doesn't modify them", "", rpp::me
CHECK(on_next_invoked == mock.get_total_on_next_count());
CHECK(on_completed_invoked == mock.get_on_completed_count());
}

SECTION("pass on_next callback with auto argument")
{
size_t on_next_invoked = 0;

obs | rpp::ops::tap([&](const auto&) { ++on_next_invoked; })
| rpp::ops::subscribe(mock);

CHECK(mock.get_received_values() == std::vector{1, 2, 3});
CHECK(mock.get_on_error_count() == 0);
CHECK(mock.get_on_completed_count() == 1);

CHECK(on_next_invoked == mock.get_total_on_next_count());
}
}
}

Expand Down