18 inline constexpr auto operator<=>(
const nothing_t&)
const =
default;
28 return std::forward<T>(t);
33 using maybe = std::variant<nothing_t, just_t<T>>;
55 template <
class F, is_maybe M>
56 constexpr auto operator()(F&& f, M&& x)
const
57 ->
maybe<std::unwrap_ref_decay_t<
decltype(
58 std::invoke(std::forward<F>(f), *std::get<1>(std::forward<M>(x))))>> {
62 return make_just(std::invoke(std::forward<F>(f), *std::get<1>(std::forward<M>(x))));
68 struct replace2nd_op {
69 template <
class U, is_maybe M>
70 constexpr auto operator()(U&& u, M&& m)
const
75 return make_just(std::forward<U>(u));
80 static constexpr fmap_op
fmap{};
91 template <is_maybe M,
class F>
92 constexpr auto operator()(M&& x, F&& f)
const
93 ->
decltype(std::invoke(std::forward<F>(f), *std::get<1>(std::forward<M>(x)))) {
97 return std::invoke(std::forward<F>(f), *std::get<1>(std::forward<M>(x)));
102 static constexpr bind_op
bind{};
116 constexpr auto operator()(U&& u)
const
118 return make_just(std::forward<U>(u));
123 struct seq_apply_op {
124 template <is_maybe M1, is_maybe M2>
125 constexpr auto operator()(M1&& f, M2&& x)
const
126 ->
decltype(
mpc::fmap(*std::get<1>(std::forward<M1>(f)), std::forward<M2>(x))) {
127 if (f.index() == 0) {
130 return mpc::fmap(*std::get<1>(std::forward<M1>(f)), std::forward<M2>(x));
137 template <
class F, is_maybe M1, is_maybe M2>
138 constexpr auto operator()(F&& f, M1&& m1, M2&& m2)
const
139 ->
maybe<std::unwrap_ref_decay_t<
decltype(
140 std::invoke(std::forward<F>(f), *std::get<1>(std::forward<M1>(m1)),
141 *std::get<1>(std::forward<M2>(m2))))>> {
142 if (m1.index() == 1 and m2.index() == 1) {
143 return make_just(std::invoke(std::forward<F>(f), *std::get<1>(std::forward<M1>(m1)),
144 *std::get<1>(std::forward<M2>(m2))));
151 static constexpr pure_op
pure{};
152 static constexpr seq_apply_op
seq_apply{};
153 static constexpr liftA2_op liftA2{};
165 constexpr auto operator()()
const ->
maybe<T1> {
171 template <is_maybe M1, is_maybe M2>
172 requires std::same_as<std::remove_cvref_t<M1>, std::remove_cvref_t<M2>>
173 constexpr auto operator()(M1&& m1, M2&& m2)
const
174 -> std::remove_cvref_t<M1> {
175 return (m1.index() == 1 ? m1 : m2);
179 static constexpr empty_op
empty{};
180 static constexpr combine_op
combine{};
std::variant< nothing_t, just_t< T > > maybe
data Maybe a = Nothing | Just a
Definition: maybe.hpp:33
constexpr auto discard2nd
discard2nd :: f a -> f b -> f a
Definition: applicative.hpp:182
constexpr partial< detail::discard1st_opt_op > discard1st_opt
discard1st :: f a -> f b -> f b
Definition: applicative.hpp:194
constexpr partial< detail::fmap_op > fmap
fmap :: (a -> b) -> f a -> f b
Definition: applicative.hpp:161
constexpr partial< detail::bind_op > bind
bind :: forall a b. m a -> (a -> m b) -> m b
Definition: monad.hpp:45
constexpr partial< detail::discard1st_op > discard1st
discard1st :: f a -> f b -> f b
Definition: applicative.hpp:108
constexpr partial< detail::replace2nd_op > replace2nd
replace2nd :: a -> f b -> f a
Definition: functor.hpp:53
constexpr detail::empty_op< F > empty
empty :: f a
Definition: alternative.hpp:71
constexpr partial< detail::combine_op > combine
combine :: f a -> f a -> f a
Definition: alternative.hpp:74
constexpr partial< detail::discard2nd_op > discard2nd
discard2nd :: f a -> f b -> f a
Definition: applicative.hpp:105
constexpr partial< detail::seq_apply_op > seq_apply
seq_apply :: f (a -> b) -> f a -> f b
Definition: applicative.hpp:99
constexpr partial< detail::pure_op< F > > pure
pure :: a -> f a
Definition: applicative.hpp:96
class Applicative f => Alternative f where
Definition: alternative.hpp:14
class Functor f => Applicative f where
Definition: applicative.hpp:18
class Functor f where
Definition: functor.hpp:14
class Applicative m => Monad m where
Definition: monad.hpp:15
A class that holds a single value.
Definition: single.hpp:15