{"id":267097,"date":"2015-10-29T20:02:03","date_gmt":"2015-10-29T17:02:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=267097"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=267097","title":{"rendered":"\u041c\u043e\u043d\u0430\u0434\u0430 Maybe \u043d\u0430 \u0441\u0442\u0435\u0440\u043e\u0438\u0434\u0430\u0445"},"content":{"rendered":"<p>       \u041f\u0440\u043e \u043c\u043e\u043d\u0430\u0434\u044b \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0431\u044b\u043b\u043e <a href=\"http:\/\/habrahabr.ru\/post\/127556\/\">\u0443\u0436\u0435<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/209510\/\">\u0441\u0442\u043e\u043b\u044c\u043a\u043e<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/231801\/\">\u043c\u043d\u043e\u0433\u043e<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/238171\/\">\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/184722\/\">\u0447\u0442\u043e<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/212955\/\">\u043c\u043d\u0435 <\/a> <a href=\"http:\/\/habrahabr.ru\/company\/cit\/blog\/262055\/\">\u043a\u0430\u0436\u0435\u0442\u0441\u044f<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/247997\/\">\u043d\u0435 <\/a> <a href=\"http:\/\/habrahabr.ru\/post\/112464\/\">\u0445\u0432\u0430\u0442\u0430\u0435\u0442<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/147363\/\">\u0435\u0449\u0435 <\/a>\u043e\u0434\u043d\u043e\u0439.<\/p>\n<p>  \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u043d\u0430\u0434\u0430, \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0443 \u043e\u0434\u043d\u0443 \u0437\u0430\u0431\u0430\u0432\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u043d\u0430\u0434\u044b Maybe (\u043c\u044b \u0436\u0435 \u0432 \u0445\u0430\u0431\u0435 \u00ab\u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u00bb?).<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442:  <\/p>\n<pre><code class=\"cs\">public delegate T IMaybe&lt;out T&gt;(); <\/code><\/pre>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f (Optional type).<\/p>\n<p>  \u041c\u043e\u043d\u0430\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u043c\u0435\u0442\u044c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u2014 Return \u0438 Bind. \u041f\u0435\u0440\u0432\u044b\u0439 \u00ab\u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u00bb \u043d\u0435\u043c\u043e\u043d\u0430\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043c\u043e\u043d\u0430\u0434\u0443, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u043c\u043e\u043d\u0430\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u043c\u0438 (extension methods) \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0438\u043f\u0430 \u0438 \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432 \u043d\u0435\u0433\u043e:  <\/p>\n<pre><code class=\"cs\">public static class Maybe  { } <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u2014 Return \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f. \u0418\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0433\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442:  <\/p>\n<pre><code class=\"cs\">public static IMaybe&lt;T&gt; Return&lt;T&gt;(T x) { \treturn () =&gt; x; } <\/code><\/pre>\n<p>  \u0423 Maybe \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e \u043d\u0435\u0447\u0442\u043e, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>public static IMaybe&lt;T&gt; Nothing&lt;T&gt;() { \treturn () =&gt; { throw new InvalidOperationException(&quot;\u041d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&quot;); }; } <\/code><\/pre>\n<p>  \u0412\u0442\u043e\u0440\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0443 \u043c\u043e\u043d\u0430\u0434\u044b \u2014 Bind \u2014 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0415\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430:  <\/p>\n<pre><code class=\"cs\">public static IMaybe&lt;TResult&gt; Bind&lt;TArg, TResult&gt;(this IMaybe&lt;TArg&gt; maybe, Func&lt;TArg, IMaybe&lt;TResult&gt;&gt; func) <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441 \u043d\u0438\u043c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u043f\u043e\u0431\u043b\u0438\u0436\u0435. <\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2014 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0435\u0440\u0432\u043e\u0435 \u043c\u043e\u043d\u0430\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u043d\u0430\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0435 \u043c\u043e\u043d\u0430\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 Bind \u0434\u043e\u043b\u0436\u043d\u0430 \u0443\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043c\u043e\u043d\u0430\u0434\u044b. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0434\u0435\u043b\u0435\u0433\u0430\u0442.<\/p>\n<pre><code class=\"cs\">public static IMaybe&lt;TResult&gt; Bind&lt;TArg, TResult&gt;(this IMaybe&lt;TArg&gt; maybe, Func&lt;TArg, IMaybe&lt;TResult&gt;&gt; func) {     return () =&gt; {        var value = maybe();        var newMaybe = func(value);        return newMaybe();            }; } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u044c. \u041c\u0435\u0442\u043e\u0434 Bind \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0433 \u0438\u043c\u0435\u0442\u044c \u0438 \u0442\u0430\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"cs\">public static IMaybe&lt;TResult&gt; Bind&lt;TArg, TResult&gt;(this IMaybe&lt;TArg&gt; maybe, Func&lt;TArg, IMaybe&lt;TResult&gt;&gt; func) { \t\/\/ \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f! \treturn func(maybe()); } <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0443\u0442 \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0432\u043e\u0445. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c Nothing, \u0442\u043e \u043c\u0435\u0442\u043e\u0434 Bind \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430. \u041d\u043e \u043c\u044b-\u0442\u043e \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b Bind <i>\u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043b<\/i> \u0434\u0432\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 <i>\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043b<\/i> \u0438\u0445. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 Bind \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043b\u043e\u0436\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u043e\u043d\u0430\u0434\u044b \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0434 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u043c\u043e\u043d\u0430\u0434\u044b \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044e \u043d\u0430\u0448\u0435\u0439 Maybe.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e Maybe: Select, Where, SelectMany<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 Select \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043d\u0430\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0432\u043d\u0443\u0442\u0440\u0438 Maybe. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Bind \u0438 Return:  <\/p>\n<pre><code class=\"cs\">public static IMaybe&lt;TResult&gt; Select&lt;TArg, TResult&gt;(this IMaybe&lt;TArg&gt; maybe, Func&lt;TArg, TResult&gt; func) { \treturn maybe.Bind(value =&gt; Return(func(value))); } <\/code><\/pre>\n<p>  Where \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 Maybe \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Nothing, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0443:  <\/p>\n<pre><code class=\"cs\">public static IMaybe&lt;T&gt; Where&lt;T&gt;(this IMaybe&lt;T&gt; maybe, Func&lt;T, bool&gt; predicate) { \treturn maybe.Bind(x =&gt; predicate(x) ? Return(x) : Nothing&lt;T&gt;()); } <\/code><\/pre>\n<p>  SelectMany \u2014 \u044d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 Bind, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Linq \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441. \u041e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e Bind \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0431\u043e\u0438\u0445 \u043c\u043e\u043d\u0430\u0434:<\/p>\n<pre><code>public static IMaybe&lt;TC&gt; SelectMany&lt;TA, TB, TC&gt;(this IMaybe&lt;TA&gt; ma, Func&lt;TA, IMaybe&lt;TB&gt;&gt; maybeSelector, Func&lt;TA, TB, TC&gt; resultSelector) { \treturn ma.Bind(a =&gt; maybeSelector(a).Select(b =&gt; resultSelector(a, b))); } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u044b Select, Where \u0438 SelectMany \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e\u0442 \u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e Maybe \u2014 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e Bind, Return \u0438 \u043f\u0443\u0441\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (Nothing \u0434\u043b\u044f Maybe). \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e Maybe \u2014 \u0438 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0431\u044b \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u044b. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u043c\u043e\u043d\u0430\u0434\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 List:<\/p>\n<pre><code>public static IEnumerable&lt;T&gt; Return&lt;T&gt;(T x) { \treturn new[] { x }; }  public static IEnumerable&lt;T&gt; Nothing&lt;T&gt;() { \tyield break; }  public static IEnumerable&lt;TResult&gt; Bind&lt;TArg, TResult&gt;(this IEnumerable&lt;TArg&gt; m, Func&lt;TArg, IEnumerable&lt;TResult&gt;&gt; func) { \tforeach (var arg in m) \t{ \t\tforeach (var result in func(arg)) \t\t{ \t\t\tyield return result; \t\t} \t} } <\/code><\/pre>\n<p>  \u2026 \u0438 \u0441\u043d\u043e\u0432\u0430 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0431\u044b \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435. \u0415\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0438 \u0442\u0430\u0439\u043f-\u043a\u043b\u0430\u0441\u0441\u044b (type class), \u043c\u044b \u0431\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0430\u0434 \u0442\u0430\u0439\u043f-\u043a\u043b\u0430\u0441\u0441\u043e\u043c Monad (\u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f* \u0432 \u0425\u0430\u0441\u043a\u0435\u043b\u043b\u0435) (*\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442).<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u2014 \u044d\u0442\u043e, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e Maybe:<\/p>\n<pre><code class=\"cs\">var one = Maybe.Return(1); var nothing = Maybe.Nothing&lt;int&gt;(); var nothing2 = \tfrom ax in one \tfrom ay in nothing \tselect ax + ay;  var two = one.Where(z =&gt; z &gt; 0).Select(z =&gt; z + 1);  Console.WriteLine(one()); Console.WriteLine(two()); Console.WriteLine(nothing2()); <\/code><\/pre>\n<p>  \u0423 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043c\u043e\u043d\u0430\u0434\u044b, \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u0447\u0442\u043e \u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0442\u0440\u0435\u0445 \u0441\u0442\u0440\u043e\u0447\u043a\u0430\u0445. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u00ab\u041d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb.<\/p>\n<p>  \u0412\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c <a href=\"https:\/\/dotnetfiddle.net\/jaWnj8\">\u0437\u0434\u0435\u0441\u044c<\/a>.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/269717\/\"> http:\/\/habrahabr.ru\/post\/269717\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041f\u0440\u043e \u043c\u043e\u043d\u0430\u0434\u044b \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0431\u044b\u043b\u043e <a href=\"http:\/\/habrahabr.ru\/post\/127556\/\">\u0443\u0436\u0435<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/209510\/\">\u0441\u0442\u043e\u043b\u044c\u043a\u043e<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/231801\/\">\u043c\u043d\u043e\u0433\u043e<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/238171\/\">\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/184722\/\">\u0447\u0442\u043e<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/212955\/\">\u043c\u043d\u0435 <\/a> <a href=\"http:\/\/habrahabr.ru\/company\/cit\/blog\/262055\/\">\u043a\u0430\u0436\u0435\u0442\u0441\u044f<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/247997\/\">\u043d\u0435 <\/a> <a href=\"http:\/\/habrahabr.ru\/post\/112464\/\">\u0445\u0432\u0430\u0442\u0430\u0435\u0442<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/147363\/\">\u0435\u0449\u0435 <\/a>\u043e\u0434\u043d\u043e\u0439.<\/p>\n<p>  \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u043d\u0430\u0434\u0430, \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0443 \u043e\u0434\u043d\u0443 \u0437\u0430\u0431\u0430\u0432\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u043d\u0430\u0434\u044b Maybe (\u043c\u044b \u0436\u0435 \u0432 \u0445\u0430\u0431\u0435 \u00ab\u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u00bb?).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-267097","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=267097"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267097\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}