mirror of
https://github.com/trafi/maybe-result-cpp
synced 2024-11-23 02:43:26 +01:00
Add map function to pass another ok result for success case.
This commit is contained in:
parent
8b0e3f0e13
commit
89c1bc061b
@ -220,6 +220,9 @@ namespace maybe {
|
||||
template <typename F>
|
||||
constexpr auto map(F f) noexcept -> maybe::result<typename std::result_of<F(T)>::type, E>;
|
||||
|
||||
template <typename U>
|
||||
constexpr auto map_value(U value) noexcept -> maybe::result<U, E>;
|
||||
|
||||
/**
|
||||
* Maps a result<T, E> to result<T, U> (where U is return value of F(E)) by applying a
|
||||
* function to a
|
||||
|
@ -109,6 +109,17 @@ constexpr auto maybe::result<T, E>::map(F f) noexcept
|
||||
return return_result_t::ok(f(std::forward<T>(ok_value())));
|
||||
};
|
||||
|
||||
template <typename T, typename E>
|
||||
template <typename U>
|
||||
constexpr auto maybe::result<T, E>::map_value(U value) noexcept -> maybe::result<U, E>
|
||||
{
|
||||
if (is_err()) {
|
||||
return maybe::result<U, E>::err(std::forward<E>(err_value()));
|
||||
}
|
||||
|
||||
return maybe::result<U, E>::ok(std::forward<U>(value));
|
||||
};
|
||||
|
||||
template <typename T, typename E>
|
||||
template <typename F>
|
||||
constexpr auto maybe::result<T, E>::map_err(F f) noexcept
|
||||
|
Loading…
Reference in New Issue
Block a user