Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
// This file is part of Desktop App Toolkit,
|
|
// a set of libraries for developing nice desktop applications.
|
|
//
|
|
// For license and copyright information please follow this link:
|
|
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
|
//
|
|
#pragma once
|
|
|
|
#include "base/optional.h"
|
|
#include "base/variant.h"
|
|
#include <rpl/map.h>
|
|
#include <rpl/producer.h>
|
|
|
|
namespace rpl {
|
|
|
|
template <
|
|
typename Value,
|
|
typename Error,
|
|
typename GeneratorTest,
|
|
typename GeneratorA,
|
|
typename GeneratorB>
|
|
inline auto conditional(
|
|
rpl::producer<bool, Error, GeneratorTest> &&test,
|
|
rpl::producer<Value, Error, GeneratorA> &&a,
|
|
rpl::producer<Value, Error, GeneratorB> &&b) {
|
|
return rpl::combine(
|
|
std::move(test),
|
|
std::move(a),
|
|
std::move(b)
|
|
) | rpl::map([](bool test, Value &&a, Value &&b) {
|
|
return test ? std::move(a) : std::move(b);
|
|
});
|
|
//struct conditional_state {
|
|
// std::optional<Value> a;
|
|
// std::optional<Value> b;
|
|
// char state = -1;
|
|
// int working = 3;
|
|
//};
|
|
//return rpl::make_producer<Value, Error>([
|
|
// test = std::move(test),
|
|
// a = std::move(a),
|
|
// b = std::move(b)
|
|
//](const auto &consumer) mutable {
|
|
// auto result = lifetime();
|
|
// const auto state = result.make_state<conditional_state>();
|
|
// result.add(std::move(test).start())
|
|
// return result;
|
|
//});
|
|
}
|
|
|
|
} // namespace rpl
|