{"id":295099,"date":"2019-11-24T15:00:16","date_gmt":"2019-11-24T15:00:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=295099"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=295099","title":{"rendered":"\u0424\u043e\u0440\u043c\u0443\u043b\u044b \u0438 \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u044b"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/477222\/\">\n<h3>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0443\u043b\u0430\u043c\u0438<\/h3>\n<p>  \u041d\u0430\u043c \u0432 \u0444\u0438\u043d\u0442\u0435\u0445\u0435 \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u043a\u0443\u0440\u0441 \u043e\u0431\u043c\u0435\u043d\u0430 \u0432\u0430\u043b\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0438\u043b\u0438 \u043d\u0435\u0442. \u042d\u0442\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f, \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u0447\u0442\u043e\u0431\u044b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435, \u0447\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u044b\u0441\u044f\u0447 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0433\u0434\u0430 \u043a\u0443\u0440\u0441 \u043e\u0431\u043c\u0435\u043d\u0430 \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430 \u0434\u0432\u0430 \u043a \u043e\u0434\u043d\u043e\u043c\u0443. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0433\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"ruby\">def notify?(rate) when rate &gt; 2.0, do: true def notify?(_), do: false <\/code><\/pre>\n<p>  \u041c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0438\u043b\u0438 \u043c\u0435\u043d\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u0430, <a href=\"https:\/\/hexdocs.pm\/elixir\/master\/Code.html#eval_string\/3\"><code>Code.eval_string\/3<\/code><\/a> \u043a\u0430\u043a-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043e\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0435\u0440\u0442\u043e\u0432 \u0440\u0430\u0437 \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0430\u043f\u0440\u0430\u0441\u043d\u0430\u044f \u0442\u0440\u0430\u0442\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u044b. \u041a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0441\u0443\u0433\u0443\u0431\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 10000 \u043a\u0443\u0440\u0441\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043f\u0430\u0440 \u0435\u0436\u0435\u0441\u0435\u043a\u0443\u043d\u0434\u043d\u043e.<\/p>\n<p>  \u0422\u0430\u043a \u043c\u044b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043f\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b. \u041a\u0440\u043e\u0448\u0435\u0447\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/hexdocs.pm\/formulae\/Formulae.html#content\"><code>formulae<\/code><\/a> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u0443, \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0432 \u043a\u043e\u0434,\u00a0\u2014 \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b.<\/p>\n<p>  <b>NB<\/b> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0430\u0442\u043e\u043c\u043e\u0432 \u0438 \u0441\u043b\u0435\u043f\u043e\u0435 \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0435 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0447\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0430\u0442\u043e\u043c\u043d\u043e\u0439 DoS-\u0430\u0442\u0430\u043a\u0435 \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443 \u044d\u0440\u043b\u0430\u043d\u0433\u0430 \u043f\u0440\u0438 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0434\u043e\u043b\u0433\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0439 \u0448\u0430\u0433 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>0.01<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 200 \u0442\u044b\u0441\u044f\u0447 \u0430\u0442\u043e\u043c\u043e\u0432 \u043f\u0440\u0438 \u0445\u0443\u0434\u0448\u0435\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<h3>\u041b\u0435\u043d\u0438\u0432\u044b\u0435 \u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u044b<\/h3>\n<p>  \u041d\u043e \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0446\u0435\u043b\u044c \u044d\u0442\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0438\u00a0\u2014 \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043f\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0443\u043b\u0430\u0445. \u0414\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0412\u043d\u0435\u0437\u0430\u043f\u043d\u043e, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Elixir \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041d\u0443, \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u0437 Ruby (<a href=\"https:\/\/ruby-doc.org\/core\/Array.html#method-i-combination\"><code>Array#combination<\/code><\/a> \u0438 \u0440\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u0438\u0447\u043a\u043e\u0432). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044d\u0442\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432. \u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0433\u043b\u043e\u0445\u043b\u0438 \u0432 \u0440\u0430\u0439\u043e\u043d\u0435 \u0442\u0440\u0438\u0434\u0446\u0430\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435, \u043f\u0435\u0440\u043c\u0443\u0442\u0430\u0446\u0438\u0438\u00a0\u2014 \u0438 \u0442\u043e\u0433\u043e \u0440\u0430\u043d\u044c\u0448\u0435.<\/p>\n<p>  \u041d\u0443, \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e, \u0447\u0442\u043e \u0443\u0436 \u0442\u0443\u0442; \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u0442\u0430\u043b \u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Stream. \u041e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u044f \u0434\u0443\u043c\u0430\u043b. \u042f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u043a\u043e\u0434\u0430 \u043d\u0438\u0436\u0435<\/p>\n<pre><code class=\"ruby\">list = ~w[a b c d e]a  combinations =   Stream.transform(Stream.with_index(list), :ok, fn {i1, idx1}, :ok -&gt;     {Stream.transform(Stream.with_index(list), :ok, fn         {_, idx2}, :ok when idx2 &lt;= idx1 -&gt;           {[], :ok}          {i2, idx2}, :ok -&gt;           {Stream.transform(Stream.with_index(list), :ok, fn             {_, idx3}, :ok when idx3 &lt;= idx2 -&gt;               {[], :ok}              {i3, idx3}, :ok -&gt;               {Stream.transform(Stream.with_index(list), :ok, fn                   {_, idx4}, :ok when idx4 &lt;= idx3 -&gt;                     {[], :ok}                    {i4, _idx4}, :ok -&gt;                     {[[i1, i2, i3, i4]], :ok}                 end), :ok}           end), :ok}       end), :ok}   end) <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439. \u041d\u0443, \u044d\u0442\u043e \u0443\u0436\u0435 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0438\u043c\u043e: \u043d\u0430 \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441\u044b, \u0434\u0430?<\/p>\n<p>  \u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u0440\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u0423\u0441\u043f\u0435\u0448\u043d\u0430\u044f \u0432\u0435\u0442\u043a\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a. \u0411\u044b\u0441\u0442\u0440\u044b\u0439 \u0432\u044b\u0431\u0440\u043e\u0441 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0418 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c. \u041f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c AST \u0434\u043b\u044f \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e.<\/p>\n<p>  \u042d\u0442\u043e \u0442\u043e\u0442 \u0440\u0435\u0434\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <a href=\"https:\/\/hexdocs.pm\/elixir\/master\/Kernel.SpecialForms.html?#quote\/2\"><code>Kernel.SpecialForms.quote\/2<\/code><\/a>, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u0441\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u043f\u043e\u0448\u0435\u043b \u043f\u043e \u043f\u0443\u0442\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u0435\u043d\u0438\u044f: \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043b\u0435\u043f\u0438\u0442\u044c \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 \u0433\u043e\u043b\u044b\u0439 AST. <\/p>\n<p>  \u042f \u043d\u0430\u0447\u0430\u043b \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u043b <code>quote do:<\/code> \u043d\u0430 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435, \u0438 \u0434\u043e \u0440\u0435\u0437\u0438 \u0432 \u0433\u043b\u0430\u0437\u0430\u0445 \u0438\u0437\u0443\u0447\u0438\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0414\u0430, \u0435\u0441\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438. \u041d\u0443, \u043f\u043e\u0435\u0445\u0430\u043b\u0438.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043d\u0430\u0434\u043e \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u0430\u0440\u043a\u0430\u0441\u0430.<\/p>\n<pre><code class=\"ruby\">defmacrop mapper(from, to, fun),   do: quote(do: Enum.map(Range.new(unquote(from), unquote(to)), unquote(fun)))  @spec combinations(list :: list(), count :: non_neg_integer()) :: {Stream.t(), :ok} defmacro combinations(l, n) do   Enum.reduce(n..1, {[mapper(1, n, &var\/1)], :ok}, fn i, body -&gt;     stream_combination_transform_clause(i, l, body)   end) end <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u043c\u044b\u0441\u043b\u0438\u0442\u044c \u0432 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u0445 \u043d\u0435 \u043a\u043e\u0434\u0430, \u043d\u043e AST, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438. \u042d\u0442\u043e \u0432\u0435\u0441\u0435\u043b\u043e!<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"ruby\">def var(i), do: {:&quot;i_#{i}&quot;, [], Elixir} def idx(i), do: {:&quot;idx_#{i}&quot;, [], Elixir} <\/code><\/pre>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043a\u0443\u0441\u043e\u043a AST, \u0432\u044b\u0434\u0440\u0430\u043d\u043d\u044b\u0439 \u0438\u0437 \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"ruby\">def sink_combination_clause(i) when i &gt; 1 do   {:-&gt;, [],     [       [         {:when, [],         [           {\u200b{:_, [], Elixir}, idx(i)},           :ok,           {:&lt;=, [context: Elixir, import: Kernel], [idx(i), idx(i - 1)]}         ]}       ],       {[], :ok}     ]} end <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u043a\u0443\u0441\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u0435:<\/p>\n<pre><code class=\"ruby\">def sink_combination_clauses(1, body) do   [{:-&gt;, [], [[{var(1), idx(1)}, :ok], body]}] end  def sink_combination_clauses(i, body) when i &gt; 1 do   Enum.reverse([     {:-&gt;, [], [[{var(i), idx(i)}, :ok], body]}     | Enum.map(2..i, &sink_combination_clause\/1)   ]) end <\/code><\/pre>\n<p>  \u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u043d\u0435\u0448\u043d\u044f\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e.<\/p>\n<pre><code class=\"ruby\">def stream_combination_transform_clause(i, l, body) do   clauses = sink_combination_clauses(i, body)    {\u200b{\u200b{:., [], [{:__aliases__, [alias: false], [:Stream]}, :transform]}, [],     [       {\u200b{:., [], [{:__aliases__, [alias: false], [:Stream]}, :with_index]}, [], [l]},       :ok,       {:fn, [], clauses}     ]}, :ok} end <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u00a0\u2014\u00a0\u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e, \u0434\u0430? \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/am-kantox\/formulae\/blob\/master\/lib\/combinators\/helper.ex\">\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<h3>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u044d\u0442\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c-\u0442\u043e? \u041d\u0443, \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\">l = for c &lt;- ?a..?z, do: &lt;&lt;c&gt;&gt; # letters list with {stream, :ok} &lt;- Formulae.Combinators.Stream.permutations(l, 12),   do: stream |&gt; Stream.take_every(26) |&gt; Enum.take(2)  #\u21d2 [[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;k&quot;, &quot;l&quot;], #   [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;l&quot;, &quot;w&quot;]] <\/code><\/pre>\n<p>  \u041c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043a\u043e\u0440\u043c\u0438\u0442\u044c <a href=\"https:\/\/hexdocs.pm\/flow\/\"><code>Flow<\/code><\/a> \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0414\u0430, \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0438 \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u043e, \u043d\u043e, \u043a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u0442\u043e\u0438\u0442 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u043d\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0430 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u043e\u0447\u044c\u044e, \u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0442\u043e\u0440\u043e\u043f\u043b\u0438\u0432\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0438 \u043a\u0443\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e AST \u0432 Elixir\u00a0\u2014\u00a0\u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435, \u044f \u043d\u0430 \u043d\u0435\u043c \u0441\u043e\u0431\u0430\u043a\u0443 \u0441\u044a\u0435\u043b.<\/p><\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/477222\/\"> https:\/\/habr.com\/ru\/post\/477222\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/477222\/\">\n<h3>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0443\u043b\u0430\u043c\u0438<\/h3>\n<p>  \u041d\u0430\u043c \u0432 \u0444\u0438\u043d\u0442\u0435\u0445\u0435 \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u043a\u0443\u0440\u0441 \u043e\u0431\u043c\u0435\u043d\u0430 \u0432\u0430\u043b\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0438\u043b\u0438 \u043d\u0435\u0442. \u042d\u0442\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f, \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u0447\u0442\u043e\u0431\u044b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435, \u0447\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u044b\u0441\u044f\u0447 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0433\u0434\u0430 \u043a\u0443\u0440\u0441 \u043e\u0431\u043c\u0435\u043d\u0430 \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430 \u0434\u0432\u0430 \u043a \u043e\u0434\u043d\u043e\u043c\u0443. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0433\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"ruby\">def notify?(rate) when rate &gt; 2.0, do: true def notify?(_), do: false <\/code><\/pre>\n<p>  \u041c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0438\u043b\u0438 \u043c\u0435\u043d\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e.  <\/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-295099","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295099","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=295099"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295099\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}