6#ifndef SL_UTILITY_NULLABLES_AND_THEN_HPP
7#define SL_UTILITY_NULLABLES_AND_THEN_HPP
14namespace sl::nullables::detail
16 template <input_nullable TInputNullable, std::invocable<dereference_result_t<TInputNullable>> TFunc>
17 requires nullable<std::invoke_result_t<TFunc, dereference_result_t<TInputNullable>>>
19 constexpr std::invoke_result_t<TFunc, dereference_result_t<TInputNullable>>
and_then(TInputNullable&& inputNullable, TFunc&& func)
21 using result_nullable_t = std::invoke_result_t<TFunc, dereference_result_t<TInputNullable>>;
23 if (inputNullable != null_v<TInputNullable>)
25 return std::invoke(std::forward<TFunc>(func),
unwrap(std::forward<TInputNullable>(inputNullable)));
27 return result_nullable_t{null_v<result_nullable_t>};
30 class and_then_caller_fn
33 template <input_nullable TInputNullable, std::invocable<dereference_result_t<TInputNullable>> TFunc>
34 requires nullable<std::invoke_result_t<TFunc, dereference_result_t<TInputNullable>>>
36 constexpr auto operator ()(
37 TInputNullable&& inputNullable,
40 noexcept(
noexcept(
and_then(std::declval<TInputNullable>(), std::declval<TFunc>())))
43 std::forward<TInputNullable>(inputNullable),
44 std::forward<TFunc>(func));
79 inline constexpr auto and_then = []<
class Fn>(Fn&& fn)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Fn>, Fn>)
The core algorithm helper, which executes the held operation when used as the right-hand-side of oper...
Definition: base.hpp:216
constexpr auto bind_back
Helper function, which generates a forwarding call wrapper for the given function and curries the par...
Definition: bind_back.hpp:100
constexpr auto and_then
Passes the value of the input_nullable to the function if it's not equal to its null-object....
Definition: and_then.hpp:79
constexpr detail::unwrap_fn unwrap
Retrieves the value of the given input_nullable.
Definition: base.hpp:160
Definition: adapter.hpp:19