22 template <
class S, is_Identity M>
30 template <
class S, is_Identity M>
37 template <is_State ST>
38 using State_state_t = StateT_state_t<ST>;
41 using State_monad_t = StateT_monad_t<ST>;
47 using state_type = std::decay_t<S>;
50 requires std::invocable<Fn&, state_type> and is_Identity<std::invoke_result_t<Fn&, state_type>>
51 constexpr auto operator()(Fn&& f)
const {
52 using M = std::invoke_result_t<Fn&, state_type>;
58 template <is_State ST>
59 constexpr auto operator()(ST&& x)
const noexcept
60 ->
decltype(
compose(run_Identity, run_StateT % std::forward<ST>(x))) {
61 return compose(run_Identity, run_StateT % std::forward<ST>(x));
66 inline namespace cpo {
70 inline constexpr partial<detail::run_State_op> run_State{};
83 template <is_State ST,
class T>
84 constexpr auto operator()(ST&& x, T&& t)
const noexcept(
85 noexcept(
fst(run_State % std::forward<ST>(x) % std::forward<T>(t))))
86 ->
decltype(
fst(run_State % std::forward<ST>(x) % std::forward<T>(t))) {
87 return fst(run_State % std::forward<ST>(x) % std::forward<T>(t));
92 template <is_State ST,
class T>
93 constexpr auto operator()(ST&& x, T&& t)
const noexcept(
94 noexcept(
snd(run_State % std::forward<ST>(x) % std::forward<T>(t))))
95 ->
decltype(
snd(run_State % std::forward<ST>(x) % std::forward<T>(t))) {
96 return snd(run_State % std::forward<ST>(x) % std::forward<T>(t));
101 template <
class Fn2, is_State ST>
102 constexpr auto operator()(Fn2&& f, ST&& x)
const noexcept(
103 noexcept( map_StateT %
compose(make_Identity,
compose(std::forward<Fn2>(f), run_Identity)) % std::forward<ST>(x)))
104 ->
decltype(map_StateT %
compose(make_Identity,
compose(std::forward<Fn2>(f), run_Identity)) % std::forward<ST>(x)) {
105 return map_StateT %
compose(make_Identity,
compose(std::forward<Fn2>(f), run_Identity)) % std::forward<ST>(x);
111 inline namespace cpo {
114 inline constexpr partial<detail::exec_State_op> exec_State{};
116 inline constexpr partial<detail::map_State_op> map_State{};
118 inline constexpr auto with_State = with_StateT;
constexpr partial< detail::_fst::get_op< 1 > > snd
Returns the second element of the given tuple-like object.
Definition: fst.hpp:34
constexpr partial< detail::compose_op > compose
Function composition.
Definition: compose.hpp:35
constexpr partial< detail::_fst::get_op< 0 > > fst
Returns the first element of the given tuple-like object.
Definition: fst.hpp:29
newtype StateT s m a = StateT { runStateT :: s -> m (a,s) }
Definition: stateT.hpp:29
Definition: state.hpp:100
Implements a perfect-forwarding call wrapper.
Definition: partial.hpp:63