22 template <
class T,
class Alloc>
32 template <
class T, is_list L>
33 constexpr auto operator()(T&& t, L&& l)
const {
34 auto ret = std::forward<L>(l);
35 ret.emplace_front(std::forward<T>(t));
42 constexpr auto operator()(L&& l)
const
47 auto tail = std::forward<L>(l);
48 auto head = std::move(tail.front());
50 return make_just(std::make_pair(std::move(head), std::move(tail)));
56 template <is_list L1, is_list L2>
57 constexpr auto operator()(L1&& l1, L2&& l2)
const {
58 auto head = std::forward<L1>(l1);
59 auto tail = std::forward<L2>(l2);
60 head.splice(head.end(), std::move(tail));
66 template <
class Fn, std::movable T, std::input_iterator I, std::sentinel_for<I> S>
67 constexpr auto operator()(Fn op, T&& init, I first, S last)
const -> T {
69 return std::forward<T>(init);
72 return std::invoke(op, *tmp, this->
operator()(op, std::forward<T>(init), first, last));
76 template <
class Fn, std::movable T, mpc::ranges::input_range R>
77 constexpr auto operator()(Fn&& op, T&& init, R&& r)
const -> T {
78 return this->operator()(std::forward<Fn>(op), std::forward<T>(init), mpc::ranges::begin(r),
84 inline namespace cpo {
98 template <
class Fn, is_list L>
99 constexpr auto operator()(Fn f, L&& l)
const {
100 using U = std::remove_cvref_t<std::invoke_result_t<Fn&, mpc::ranges::range_reference_t<L>>>;
101 std::list<U> ret(l.size());
102 std::transform(l.begin(), l.end(), ret.begin(), std::move(f));
107 static constexpr fmap_op
fmap{};
115 constexpr auto operator()(U&& u)
const {
116 return std::list{std::forward<U>(u)};
121 template <
class Fn, is_list L1, is_list L2>
122 constexpr auto operator()(Fn f, L1&& l1, L2&& l2)
const {
123 using U = std::remove_cvref_t<std::invoke_result_t<Fn&, mpc::ranges::range_reference_t<L1>,
124 mpc::ranges::range_reference_t<L2>>>;
125 const auto n = std::min(l1.size(), l2.size());
127 std::transform(l1.begin(), l1.end(), l2.begin(), l2.end(), ret.begin(), std::move(f));
132 static constexpr pure_op
pure{};
133 static constexpr liftA2_op
liftA2{};
155 constexpr auto operator()(
const std::list<T>& l)
const {
157 using U = holding_or_t<T, std::remove_cvref_t<
decltype(
mpc::bind(l.front(),
identity))>>;
158 return foldr(
mpc::liftA2 % cons, mpc::returns<T> % std::list<U>{}, l);
163 inline namespace cpo {
std::variant< nothing_t, just_t< T > > maybe
data Maybe a = Nothing | Just a
Definition: maybe.hpp:33
constexpr auto discard1st
discard1st :: f a -> f b -> f b
Definition: applicative.hpp:191
constexpr auto seq_apply
seq_apply :: f (a -> b) -> f a -> f b
Definition: applicative.hpp:170
constexpr auto discard2nd
discard2nd :: f a -> f b -> f a
Definition: applicative.hpp:182
constexpr partial< detail::fmap_op > fmap
fmap :: (a -> b) -> f a -> f b
Definition: applicative.hpp:161
constexpr partial< detail::liftA2_op > liftA2
liftA2 :: (a -> b -> c) -> f a -> f b -> f c
Definition: applicative.hpp:102
constexpr partial< detail::bind_op > bind
bind :: forall a b. m a -> (a -> m b) -> m b
Definition: monad.hpp:45
constexpr partial< detail::replace2nd_op > replace2nd
replace2nd :: a -> f b -> f a
Definition: functor.hpp:53
constexpr partial< std::identity > identity
Identity mapping.
Definition: identity.hpp:11
constexpr partial< detail::pure_op< F > > pure
pure :: a -> f a
Definition: applicative.hpp:96
constexpr auto replace2nd
replace2nd :: a -> f b -> f a
Definition: functor.hpp:65
class Functor f => Applicative f where
Definition: applicative.hpp:18
class Functor f where
Definition: functor.hpp:14
Implements a perfect-forwarding call wrapper.
Definition: partial.hpp:63