1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 #ifndef BOOST_HANA_TEST_LAWS_COMONAD_HPP
6 #define BOOST_HANA_TEST_LAWS_COMONAD_HPP
8 #include <boost/hana/assert.hpp>
9 #include <boost/hana/concept/comonad.hpp>
10 #include <boost/hana/concept/comparable.hpp>
11 #include <boost/hana/core/when.hpp>
12 #include <boost/hana/concept/foldable.hpp>
13 #include <boost/hana/concept/functor.hpp>
15 #include <laws/base.hpp>
18 namespace boost { namespace hana { namespace test {
19 template <typename W, typename = when<true>>
20 struct TestComonad : TestComonad<W, laws> {
21 using TestComonad<W, laws>::TestComonad;
25 struct TestComonad<W, laws> {
26 template <typename Ws>
28 hana::for_each(ws, [](auto w) {
29 static_assert(Comonad<decltype(w)>{}, "");
31 // extract(duplicate(w)) == w
32 BOOST_HANA_CHECK(hana::equal(
33 hana::extract(hana::duplicate(w)),
37 // transform(duplicate(w), extract) == w
38 BOOST_HANA_CHECK(hana::equal(
39 hana::transform(hana::duplicate(w), extract),
43 // duplicate(duplicate(w)) == transform(duplicate(w), duplicate)
44 BOOST_HANA_CHECK(hana::equal(
45 hana::duplicate(hana::duplicate(w)),
46 hana::transform(hana::duplicate(w), duplicate)
51 }}} // end namespace boost::hana::test
53 #endif // !BOOST_HANA_TEST_LAWS_COMONAD_HPP