group__group-Comonad.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!--
  2. Copyright Louis Dionne 2013-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. -->
  6. <!-- boost-no-inspect -->
  7. <!-- HTML header for doxygen 1.8.9.1-->
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  12. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  13. <meta name="generator" content="Doxygen 1.8.15"/>
  14. <title>Boost.Hana: Comonad</title>
  15. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  16. <script type="text/javascript" src="jquery.js"></script>
  17. <script type="text/javascript" src="dynsections.js"></script>
  18. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  19. <script type="text/javascript" src="resize.js"></script>
  20. <script type="text/javascript" src="navtreedata.js"></script>
  21. <script type="text/javascript" src="navtree.js"></script>
  22. <script type="text/javascript">
  23. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  24. $(document).ready(initResizable);
  25. /* @license-end */</script>
  26. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  27. <script type="text/javascript" src="search/searchdata.js"></script>
  28. <script type="text/javascript" src="search/search.js"></script>
  29. <script type="text/javascript">
  30. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  31. $(document).ready(function() { init_search(); });
  32. /* @license-end */
  33. </script>
  34. <script type="text/x-mathjax-config">
  35. MathJax.Hub.Config({
  36. extensions: ["tex2jax.js"],
  37. jax: ["input/TeX","output/HTML-CSS"],
  38. });
  39. // Copyright Louis Dionne 2013-2017
  40. // Distributed under the Boost Software License, Version 1.0.
  41. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  42. MathJax.Hub.Config({
  43. "HTML-CSS": {
  44. linebreaks: {
  45. automatic: true,
  46. width: "75% container"
  47. }
  48. }
  49. });
  50. </script><script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
  51. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  52. <!-- Additional javascript for drawing charts. -->
  53. <script type="text/javascript" src="highcharts.js"></script>
  54. <script type="text/javascript" src="highcharts-data.js"></script>
  55. <script type="text/javascript" src="highcharts-exporting.js"></script>
  56. <script type="text/javascript" src="chart.js"></script>
  57. <script type="text/javascript" src="hana.js"></script>
  58. </head>
  59. <body>
  60. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  61. <div id="titlearea">
  62. <table cellspacing="0" cellpadding="0">
  63. <tbody>
  64. <tr style="height: 56px;">
  65. <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
  66. <td style="padding-left: 0.5em;">
  67. <div id="projectname">Boost.Hana
  68. &#160;<span id="projectnumber">1.6.0</span>
  69. </div>
  70. <div id="projectbrief">Your standard library for metaprogramming</div>
  71. </td>
  72. <td> <div id="MSearchBox" class="MSearchBoxInactive">
  73. <span class="left">
  74. <img id="MSearchSelect" src="search/mag_sel.png"
  75. onmouseover="return searchBox.OnSearchSelectShow()"
  76. onmouseout="return searchBox.OnSearchSelectHide()"
  77. alt=""/>
  78. <input type="text" id="MSearchField" value="Search" accesskey="S"
  79. onfocus="searchBox.OnSearchFieldFocus(true)"
  80. onblur="searchBox.OnSearchFieldFocus(false)"
  81. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  82. </span><span class="right">
  83. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  84. </span>
  85. </div>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </div>
  91. <!-- end header part -->
  92. <!-- Generated by Doxygen 1.8.15 -->
  93. <script type="text/javascript">
  94. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  95. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  96. /* @license-end */
  97. </script>
  98. </div><!-- top -->
  99. <div id="side-nav" class="ui-resizable side-nav-resizable">
  100. <div id="nav-tree">
  101. <div id="nav-tree-contents">
  102. <div id="nav-sync" class="sync"></div>
  103. </div>
  104. </div>
  105. <div id="splitbar" style="-moz-user-select:none;"
  106. class="ui-resizable-handle">
  107. </div>
  108. </div>
  109. <script type="text/javascript">
  110. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  111. $(document).ready(function(){initNavTree('group__group-Comonad.html','');});
  112. /* @license-end */
  113. </script>
  114. <div id="doc-content">
  115. <!-- window showing the filter options -->
  116. <div id="MSearchSelectWindow"
  117. onmouseover="return searchBox.OnSearchSelectShow()"
  118. onmouseout="return searchBox.OnSearchSelectHide()"
  119. onkeydown="return searchBox.OnSearchSelectKey(event)">
  120. </div>
  121. <!-- iframe showing the search results (closed by default) -->
  122. <div id="MSearchResultsWindow">
  123. <iframe src="javascript:void(0)" frameborder="0"
  124. name="MSearchResults" id="MSearchResults">
  125. </iframe>
  126. </div>
  127. <div class="header">
  128. <div class="summary">
  129. <a href="#var-members">Variables</a> </div>
  130. <div class="headertitle">
  131. <div class="title">Comonad<div class="ingroups"><a class="el" href="group__group-concepts.html">Concepts</a></div></div> </div>
  132. </div><!--header-->
  133. <div class="contents">
  134. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  135. <p>The <code>Comonad</code> concept represents context-sensitive computations and data. </p>
  136. <p>Formally, the Comonad concept is dual to the Monad concept. But unless you're a mathematician, you don't care about that and it's fine. So intuitively, a Comonad represents context sensitive values and computations. First, Comonads make it possible to extract context-sensitive values from their context with <code>extract</code>. In contrast, Monads make it possible to wrap raw values into a given context with <code>lift</code> (from Applicative).</p>
  137. <p>Secondly, Comonads make it possible to apply context-sensitive values to functions accepting those, and to return the result as a context-sensitive value using <code>extend</code>. In contrast, Monads make it possible to apply a monadic value to a function accepting a normal value and returning a monadic value, and to return the result as a monadic value (with <code>chain</code>).</p>
  138. <p>Finally, Comonads make it possible to wrap a context-sensitive value into an extra layer of context using <code>duplicate</code>, while Monads make it possible to take a value with an extra layer of context and to strip it with <code>flatten</code>.</p>
  139. <p>Whereas <code>lift</code>, <code>chain</code> and <code>flatten</code> from Applicative and Monad have signatures </p><p class="formulaDsp">
  140. \begin{align*} \mathtt{lift}_M &amp;: T \to M(T) \\ \mathtt{chain} &amp;: M(T) \times (T \to M(U)) \to M(U) \\ \mathtt{flatten} &amp;: M(M(T)) \to M(T) \end{align*}
  141. </p>
  142. <p><code>extract</code>, <code>extend</code> and <code>duplicate</code> from Comonad have signatures </p><p class="formulaDsp">
  143. \begin{align*} \mathtt{extract} &amp;: W(T) \to T \\ \mathtt{extend} &amp;: W(T) \times (W(T) \to U) \to W(U) \\ \mathtt{duplicate} &amp;: W(T) \to W(W(T)) \end{align*}
  144. </p>
  145. <p>Notice how the "arrows" are reversed. This symmetry is essentially what we mean by Comonad being the <em>dual</em> of Monad.</p>
  146. <dl class="section note"><dt>Note</dt><dd>The <a href="https://wiki.haskell.org/Typeclassopedia#Comonad">Typeclassopedia</a> is a nice Haskell-oriented resource for further reading about Comonads.</dd></dl>
  147. <h2>Minimal complete definition </h2>
  148. <p><code>extract</code> and (<code>extend</code> or <code>duplicate</code>) satisfying the laws below. A <code>Comonad</code> must also be a <code>Functor</code>.</p>
  149. <h2>Laws </h2>
  150. <p>For all Comonads <code>w</code>, the following laws must be satisfied: </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">extract</a>(<a class="code" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">duplicate</a>(w)) == w</div><div class="line"><a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">transform</a>(<a class="code" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">duplicate</a>(w), <a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">extract</a>) == w</div><div class="line"><a class="code" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">duplicate</a>(<a class="code" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">duplicate</a>(w)) == <a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">transform</a>(<a class="code" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">duplicate</a>(w), <a class="code" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">duplicate</a>)</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>There are several equivalent ways of defining Comonads, and this one is just one that was picked arbitrarily for simplicity.</dd></dl>
  151. <h2>Refined concept </h2>
  152. <ol type="1">
  153. <li>Functor<br />
  154. Every Comonad is also required to be a Functor. At first, one might think that it should instead be some imaginary concept CoFunctor. However, it turns out that a CoFunctor is the same as a <code>Functor</code>, hence the requirement that a <code>Comonad</code> also is a <code>Functor</code>.</li>
  155. </ol>
  156. <h2>Concrete models </h2>
  157. <p><code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface.">hana::lazy</a></code> </p>
  158. <table class="memberdecls">
  159. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
  160. Variables</h2></td></tr>
  161. <tr class="memitem:ga181751278bd19a4bfc3c08bd7ddef399"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">boost::hana::duplicate</a></td></tr>
  162. <tr class="memdesc:ga181751278bd19a4bfc3c08bd7ddef399"><td class="mdescLeft">&#160;</td><td class="mdescRight">Add an extra layer of comonadic context to a comonadic value.Given a value already in a comonadic context, <code>duplicate</code> wraps this value with an additional layer of comonadic context. This can be seen as the dual operation to <code>flatten</code> from the Monad concept. <a href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">More...</a><br /></td></tr>
  163. <tr class="separator:ga181751278bd19a4bfc3c08bd7ddef399"><td class="memSeparator" colspan="2">&#160;</td></tr>
  164. <tr class="memitem:gaf44692351fd9fe4e76815dfef6ff4478"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Comonad.html#gaf44692351fd9fe4e76815dfef6ff4478">boost::hana::extend</a></td></tr>
  165. <tr class="memdesc:gaf44692351fd9fe4e76815dfef6ff4478"><td class="mdescLeft">&#160;</td><td class="mdescRight">Comonadic application of a function to a comonadic value.Given a comonadic value and a function accepting a comonadic input, <code>extend</code> returns the result of applying the function to that input inside the comonadic context. <a href="group__group-Comonad.html#gaf44692351fd9fe4e76815dfef6ff4478">More...</a><br /></td></tr>
  166. <tr class="separator:gaf44692351fd9fe4e76815dfef6ff4478"><td class="memSeparator" colspan="2">&#160;</td></tr>
  167. <tr class="memitem:ga307479a91a21b7ab06a2bc746b003dcc"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">boost::hana::extract</a></td></tr>
  168. <tr class="memdesc:ga307479a91a21b7ab06a2bc746b003dcc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Extract a value in a given comonadic context.Given a value inside a comonadic context, extract it from that context, performing whatever effects are mandated by that context. This can be seen as the dual operation to the <code>lift</code> method of the Applicative concept. <a href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">More...</a><br /></td></tr>
  169. <tr class="separator:ga307479a91a21b7ab06a2bc746b003dcc"><td class="memSeparator" colspan="2">&#160;</td></tr>
  170. </table>
  171. <h2 class="groupheader">Variable Documentation</h2>
  172. <a id="ga181751278bd19a4bfc3c08bd7ddef399"></a>
  173. <h2 class="memtitle"><span class="permalink"><a href="#ga181751278bd19a4bfc3c08bd7ddef399">&#9670;&nbsp;</a></span>duplicate</h2>
  174. <div class="memitem">
  175. <div class="memproto">
  176. <table class="memname">
  177. <tr>
  178. <td class="memname">constexpr auto boost::hana::duplicate</td>
  179. </tr>
  180. </table>
  181. </div><div class="memdoc">
  182. <p><code>#include &lt;<a class="el" href="fwd_2duplicate_8hpp.html">boost/hana/fwd/duplicate.hpp</a>&gt;</code></p>
  183. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; w) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  184. <p>Add an extra layer of comonadic context to a comonadic value.Given a value already in a comonadic context, <code>duplicate</code> wraps this value with an additional layer of comonadic context. This can be seen as the dual operation to <code>flatten</code> from the Monad concept. </p>
  185. <h2>Signature </h2>
  186. <p>Given a Comonad <code>W</code>, the signature is \( \mathtt{duplicate} : W(T) \to W(W(T)) \)</p>
  187. <dl class="params"><dt>Parameters</dt><dd>
  188. <table class="params">
  189. <tr><td class="paramname">w</td><td>The value to wrap in an additional level of comonadic context.</td></tr>
  190. </table>
  191. </dd>
  192. </dl>
  193. <h2>Example </h2>
  194. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="duplicate_8hpp.html">boost/hana/duplicate.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="extract_8hpp.html">boost/hana/extract.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lazy_8hpp.html">boost/hana/lazy.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> constexpr <span class="keyword">auto</span> very_lazy = <a class="code" href="group__group-Comonad.html#ga181751278bd19a4bfc3c08bd7ddef399">hana::duplicate</a>(hana::make_lazy(3));</div><div class="line"> static_assert(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(very_lazy)) == 3, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">}</div></div><!-- fragment -->
  195. </div>
  196. </div>
  197. <a id="gaf44692351fd9fe4e76815dfef6ff4478"></a>
  198. <h2 class="memtitle"><span class="permalink"><a href="#gaf44692351fd9fe4e76815dfef6ff4478">&#9670;&nbsp;</a></span>extend</h2>
  199. <div class="memitem">
  200. <div class="memproto">
  201. <table class="memname">
  202. <tr>
  203. <td class="memname">constexpr auto boost::hana::extend</td>
  204. </tr>
  205. </table>
  206. </div><div class="memdoc">
  207. <p><code>#include &lt;<a class="el" href="fwd_2extend_8hpp.html">boost/hana/fwd/extend.hpp</a>&gt;</code></p>
  208. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; w, <span class="keyword">auto</span>&amp;&amp; f) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  209. <p>Comonadic application of a function to a comonadic value.Given a comonadic value and a function accepting a comonadic input, <code>extend</code> returns the result of applying the function to that input inside the comonadic context. </p>
  210. <h2>Signature </h2>
  211. <p>Given a Comonad <code>W</code> and a function of type \( W(T) \to U \), the signature is \( \mathtt{extend} : W(T) \times (W(T) \to U) \to W(U) \)</p>
  212. <dl class="params"><dt>Parameters</dt><dd>
  213. <table class="params">
  214. <tr><td class="paramname">w</td><td>A comonadic value to call the function with.</td></tr>
  215. <tr><td class="paramname">f</td><td>A function of signature \( W(T) \to U \) to be applied to its comonadic argument inside the comonadic context.</td></tr>
  216. </table>
  217. </dd>
  218. </dl>
  219. <h2>Example </h2>
  220. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="eval_8hpp.html">boost/hana/eval.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="extend_8hpp.html">boost/hana/extend.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="extract_8hpp.html">boost/hana/extract.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lazy_8hpp.html">boost/hana/lazy.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;functional&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;istream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sstream&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line">T read_one(std::istream&amp; s) {</div><div class="line"> T <a class="code" href="group__group-Constant.html#ga1687520692a6b0c49e3a69de2980f388">value</a>;</div><div class="line"> s &gt;&gt; <a class="code" href="group__group-Constant.html#ga1687520692a6b0c49e3a69de2980f388">value</a>;</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-Constant.html#ga1687520692a6b0c49e3a69de2980f388">value</a>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> std::stringstream s;</div><div class="line"> s &lt;&lt; <span class="stringliteral">&quot;1 2 3&quot;</span>;</div><div class="line"></div><div class="line"> <span class="keyword">auto</span> from_stream = <a class="code" href="group__group-Comonad.html#gaf44692351fd9fe4e76815dfef6ff4478">hana::extend</a>(hana::make_lazy(read_one&lt;int&gt;)(std::ref(s)), [](<span class="keyword">auto</span> i) {</div><div class="line"> <span class="keywordflow">return</span> hana::eval(i) + 1;</div><div class="line"> });</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(from_stream) == 2);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(from_stream) == 3);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(from_stream) == 4);</div><div class="line">}</div></div><!-- fragment -->
  221. </div>
  222. </div>
  223. <a id="ga307479a91a21b7ab06a2bc746b003dcc"></a>
  224. <h2 class="memtitle"><span class="permalink"><a href="#ga307479a91a21b7ab06a2bc746b003dcc">&#9670;&nbsp;</a></span>extract</h2>
  225. <div class="memitem">
  226. <div class="memproto">
  227. <table class="memname">
  228. <tr>
  229. <td class="memname">constexpr auto boost::hana::extract</td>
  230. </tr>
  231. </table>
  232. </div><div class="memdoc">
  233. <p><code>#include &lt;<a class="el" href="fwd_2extract_8hpp.html">boost/hana/fwd/extract.hpp</a>&gt;</code></p>
  234. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; w) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  235. <p>Extract a value in a given comonadic context.Given a value inside a comonadic context, extract it from that context, performing whatever effects are mandated by that context. This can be seen as the dual operation to the <code>lift</code> method of the Applicative concept. </p>
  236. <h2>Signature </h2>
  237. <p>Given a Comonad <code>W</code>, the signature is \( \mathtt{extract} : W(T) \to T \)</p>
  238. <dl class="params"><dt>Parameters</dt><dd>
  239. <table class="params">
  240. <tr><td class="paramname">w</td><td>The value to be extracted inside a comonadic context.</td></tr>
  241. </table>
  242. </dd>
  243. </dl>
  244. <h2>Example </h2>
  245. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="extract_8hpp.html">boost/hana/extract.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="placeholder_8hpp.html">boost/hana/functional/placeholder.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lazy_8hpp.html">boost/hana/lazy.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line">static_assert(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(hana::make_lazy(1)) == 1, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(hana::make_lazy(<a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1)(3)) == 4, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  246. </div>
  247. </div>
  248. </div><!-- contents -->
  249. </div><!-- doc-content -->
  250. <!--
  251. Copyright Louis Dionne 2013-2017
  252. Distributed under the Boost Software License, Version 1.0.
  253. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  254. -->
  255. <!-- boost-no-inspect -->
  256. <!-- HTML footer for doxygen 1.8.9.1-->
  257. <!-- start footer part -->
  258. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  259. <ul>
  260. </ul>
  261. </div>
  262. </body>
  263. </html>