{"id":6899,"date":"2014-06-02T17:44:43","date_gmt":"2014-06-02T14:44:43","guid":{"rendered":"http:\/\/railsware.com\/blog\/?p=6899"},"modified":"2021-08-16T14:08:22","modified_gmt":"2021-08-16T11:08:22","slug":"chainflow-refactor-your-data-processing","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/","title":{"rendered":"ChainFlow &#8211; refactor your data processing"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">TL; DR;<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This article describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and <code class=\"\" data-line=\"\">State<\/code> monad.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Motivation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Latest project I&#8217;ve been involved in deals with a lot of data processing.<br>Typical case was a method that receives a data chunk and chains it with a couple of <code class=\"\" data-line=\"\">Enumerator<\/code> methods like <code class=\"\" data-line=\"\">map<\/code>,<br><code class=\"\" data-line=\"\">each_with_objects<\/code> etc.<br>Some of the chain blocks were simple, some of them not.<br>But overall method readability degraded significantly even with a two of them chained together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;d love to have this refactored and decomposition looks like an obvious solution. Slice the big method into small ones and then chain them together. Seems straightforward.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Refactoring<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say we have a public interface with a method like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:ruby decode:true\">module Work\n  def process(data, parameter)\n    data.group_by do |point|\n      compute_point_key(point)\n    end.each_with_object({}) do |(key, points), memo|\n      memo[key] = compute_value(points, parameter)\n    end\n  end\nend\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t try to guess what is going on here &#8211; method is completely made up.<br>Let&#8217;s try to refactor it in several ways.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Iteration I: extra variable<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted lang:ruby decode:true\">module Work\n  def process(data, parameter)\n    grouped_data = group_by_key(data)\n    compute_values(grouped_data, parameter)\n  end\n\n  def group_by_key(points)\n    points.group_by do |point|\n      compute_point_key(point)\n    end\n  end\n\n  def compute_values(points, parameter)\n    points.each_with_object({}) do |(key, points), memo|\n      memo[key] = compute_value(points, parameter)\n    end\n  end\nend\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This looks fine, however notice the extra <code class=\"\" data-line=\"\">grouped_data<\/code> variable.<br>The more blocks you chain, the more extra variables you&#8217;ll have to deal with.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without extra variables it gets even more clumsy due to <code class=\"\" data-line=\"\">parameter<\/code> argument and reversed order of function invocations (from right to left).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:ruby decode:true\">def process(data, parameter)\n  compute_values (group_by_key data), parameter\nend\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Iteration II: adding state<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted lang:ruby decode:true\">class Work &lt; Struct(:data)\n  def process(parameter)\n    group_by_key\n    compute_values(parameter)\n  end\n\n  def group_by_key\n    data.group_by! do |point|\n      compute_point_key(point)\n    end\n  end\n\n  def compute_values(parameter)\n    data.each_with_object!({}) do |(key, points), memo|\n      memo[key] = compute_value(points, parameter)\n    end\n  end\nend\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now the <code class=\"\" data-line=\"\">process<\/code> looks much better (I would even say ideal). The trade-off is that <code class=\"\" data-line=\"\">group_by_key<\/code> and <code class=\"\" data-line=\"\">compute_values<\/code> are forced to use <code class=\"\" data-line=\"\">data<\/code> state variable.<br>But I don&#8217;t want to convert all my modules into classes every time I refactor the code.<br>Especially when my module is shared between other multiple classes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ChainFlow<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Could we somehow preserve the syntax from Iteration II and not constraint ourselves<br>to keep the state?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hang tight, meet ChainFlow:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:ruby decode:true\">require 'chain_flow'\n\nmodule Work\n  include ChainFlow\n\n  def process(data, parameter)\n    flow(data) do\n      group_by_key\n      compute_values(parameter)\n    end\n  end\n\n  def group_by_key(points)\n    points.group_by do |point|\n      compute_point_key(point)\n    end\n  end\n\n  def compute_values(points, parameter)\n    points.each_with_object({}) do |(key, points), memo|\n      memo[key] = compute_value(points, parameter)\n    end\n  end\nend\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have an emulation of Iteratioin II syntax beauty.<br>The order of the flow is not reversed, which is a great benefit for readability of our public interface.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another variation provided by chain_flow is similar to Arel chains we&#8217;ve got used to:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:ruby decode:true\">def process(data, parameter)\n  chain { data }.group_by_key.compute_values(parameter).fetch\nend\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice how <code class=\"\" data-line=\"\">compute_values<\/code> receives 2 arguments, but only the second (<code class=\"\" data-line=\"\">parameter<\/code>) is passed.<br>First argument is considered to be the state and being passed silently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Interested? Let&#8217;s see how it works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">It&#8217;s a kind of magic, magic, magic&#8230;<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Actually it&#8217;s a plain meta-programming.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Notice both <code class=\"\" data-line=\"\">chain<\/code> and <code class=\"\" data-line=\"\">flow<\/code> methods provided by ChainFlow module are capturing the context using closures.<br>All the following processing functions calls (<code class=\"\" data-line=\"\">group_by_key<\/code> and <code class=\"\" data-line=\"\">compute_values<\/code>) are intercepted with <code class=\"\" data-line=\"\">method_missing<\/code> behind the scenes.<br>And re-executed one-by-one in a captured context pipelining the initial data through them along with other params.<br>By omitting the first paramater in our new syntax we emphasize the fact that state (hidden under the hood) is unimportant.<br>We are concentrating not on the temporary variables to pass it through, but rather on processing calls which form the pipeline.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/github.com\/railsware\/chain_flow\" target=\"_blank\" rel=\"noreferrer noopener\">chain_flow code<\/a> itself is quite small.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Feel the Functional flavor<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The one who is into Haskell might notice that syntax provided by <code class=\"\" data-line=\"\">flow<\/code> resembles Haskell do-notation.<br>Haskell do-notation is a syntax sugar aimed to imporove the look of monadic functions composition.<br>The do-notation produces especially beautiful syntax in case <a href=\"http:\/\/learnyouahaskell.com\/for-a-few-monads-more#state\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">State monad<\/a>. See this code snippet manipulating the Stack:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:haskell decode:true\">stackManip :: State Stack Int\nstackManip = do\n  push 3\n  pop\n  pop\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">While the actual state is hidden, <code class=\"\" data-line=\"\">stackManip<\/code> composes 3 state-full computations and<br>as a result produces a computation which (when executed on an initial stack) will push 3 to the stack and then pop 2 times from it.<br>The idea behind chain_flow was to build similar syntax in Ruby.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Performance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Of course nothing comes for free. And here the trade off is the speed. <code class=\"\" data-line=\"\">eval<\/code> and other meta programming tricks are quite expensive (as well as lambdas).<br>That said, if you&#8217;re dealing with reasonable amount of data and using chain_flow only for processing method calls time\/resources necessary for the chain_flow &#8216;magic&#8217; is rather small in comparison with actual data processing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">P.S.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">See <a href=\"https:\/\/github.com\/banister\/funkify\" target=\"_blank\" rel=\"noreferrer noopener\">funkify<\/a> library which provides <em>Haskell-style partial application and composition for Ruby methods<\/em>. It relies heavily on Ruby lambdas though.<br>Good examples of monad implementations in Ruby is <a href=\"https:\/\/github.com\/pzol\/monadic\" target=\"_blank\" rel=\"noreferrer noopener\">monadic<\/a>. <a href=\"https:\/\/github.com\/aanand\/do_notation\" target=\"_blank\" rel=\"noreferrer noopener\">do-notation<\/a> provides sort of a do-notation syntax with a couple of monad implementations as well.<br>See also the <a href=\"https:\/\/github.com\/ms-ati\/docile\" target=\"_blank\" rel=\"noreferrer noopener\">docile gem<\/a> &#8211; the very first example for Array modification looks great!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After finishing this post, I came across <a href=\"http:\/\/patshaughnessy.net\/2014\/4\/8\/using-a-ruby-class-to-write-functional-code\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">awesome article<\/a> by Pat Shaugnessy. It&#8217;s good to know other people moving in the same direction. Here&#8217;s <a href=\"https:\/\/gist.github.com\/gregolsen\/0c29a4dc253830cf0ad5\" target=\"_blank\" rel=\"noreferrer noopener\">an attempt<\/a> to refactor Pat&#8217;s initial <code class=\"\" data-line=\"\">parse1<\/code> method from the article with chain_flow.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL; DR; This article describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad. Motivation Latest project I&#8217;ve been involved in deals with a lot of data processing.Typical case was a method that receives a data chunk and chains it with a couple of Enumerator&#8230;<\/p>\n","protected":false},"author":34,"featured_media":9436,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["Innokenty Mihailov"],"class_list":["post-6899","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"Describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad.\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Innokenty Mihailov\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"| Blog on Engineering, Product Management, Transparency, Culture and many more...\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"ChainFlow - refactor your data processing | Railsware Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/ChainFlow.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/ChainFlow.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2014-06-02T14:44:43+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-08-16T11:08:22+00:00\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#article\",\"name\":\"ChainFlow - refactor your data processing | Railsware Blog\",\"headline\":\"ChainFlow &#8211; refactor your data processing\",\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/ChainFlow.png\",\"width\":360,\"height\":360,\"caption\":\"ChainFlow \\u2013 refactor your data processing\"},\"datePublished\":\"2014-06-02T17:44:43+03:00\",\"dateModified\":\"2021-08-16T14:08:22+03:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#webpage\"},\"articleSection\":\"Engineering\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"position\":2,\"name\":\"Engineering\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#listItem\",\"name\":\"ChainFlow &#8211; refactor your data processing\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#listItem\",\"position\":3,\"name\":\"ChainFlow &#8211; refactor your data processing\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/Logo-circle.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#organizationLogo\",\"width\":3137,\"height\":1054,\"caption\":\"Railsware logo\"},\"image\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/\",\"name\":\"Innokenty Mihailov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#authorImage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/author-image-default-96x96.jpg\",\"width\":96,\"height\":96,\"caption\":\"Innokenty Mihailov\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#webpage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/\",\"name\":\"ChainFlow - refactor your data processing | Railsware Blog\",\"description\":\"Describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/ChainFlow.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#mainImage\",\"width\":360,\"height\":360,\"caption\":\"ChainFlow \\u2013 refactor your data processing\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/chainflow-refactor-your-data-processing\\\/#mainImage\"},\"datePublished\":\"2014-06-02T17:44:43+03:00\",\"dateModified\":\"2021-08-16T14:08:22+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"ChainFlow - refactor your data processing | Railsware Blog","description":"Describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad.","canonical_url":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#article","name":"ChainFlow - refactor your data processing | Railsware Blog","headline":"ChainFlow &#8211; refactor your data processing","author":{"@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author"},"publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/ChainFlow.png","width":360,"height":360,"caption":"ChainFlow \u2013 refactor your data processing"},"datePublished":"2014-06-02T17:44:43+03:00","dateModified":"2021-08-16T14:08:22+03:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#webpage"},"isPartOf":{"@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#webpage"},"articleSection":"Engineering"},{"@type":"BreadcrumbList","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/railsware.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","position":2,"name":"Engineering","item":"https:\/\/railsware.com\/blog\/category\/development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#listItem","name":"ChainFlow &#8211; refactor your data processing"},"previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#listItem","position":3,"name":"ChainFlow &#8211; refactor your data processing","previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}}]},{"@type":"Organization","@id":"https:\/\/railsware.com\/blog\/#organization","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","url":"https:\/\/railsware.com\/blog\/","logo":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2020\/11\/Logo-circle.png","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#organizationLogo","width":3137,"height":1054,"caption":"Railsware logo"},"image":{"@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author","url":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/","name":"Innokenty Mihailov","image":{"@type":"ImageObject","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#authorImage","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2021\/06\/author-image-default-96x96.jpg","width":96,"height":96,"caption":"Innokenty Mihailov"}},{"@type":"WebPage","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#webpage","url":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/","name":"ChainFlow - refactor your data processing | Railsware Blog","description":"Describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/railsware.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#breadcrumblist"},"author":{"@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author"},"creator":{"@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/ChainFlow.png","@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#mainImage","width":360,"height":360,"caption":"ChainFlow \u2013 refactor your data processing"},"primaryImageOfPage":{"@id":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/#mainImage"},"datePublished":"2014-06-02T17:44:43+03:00","dateModified":"2021-08-16T14:08:22+03:00"},{"@type":"WebSite","@id":"https:\/\/railsware.com\/blog\/#website","url":"https:\/\/railsware.com\/blog\/","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","inLanguage":"en-US","publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"| Blog on Engineering, Product Management, Transparency, Culture and many more...","og:type":"article","og:title":"ChainFlow - refactor your data processing | Railsware Blog","og:description":"Describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad.","og:url":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/","og:image":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/ChainFlow.png","og:image:secure_url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/ChainFlow.png","og:image:width":360,"og:image:height":360,"article:published_time":"2014-06-02T14:44:43+00:00","article:modified_time":"2021-08-16T11:08:22+00:00"},"aioseo_meta_data":{"post_id":"6899","title":"ChainFlow - refactor your data processing | Railsware Blog","description":"Describes how to refactor and improve readability of complex data processing with syntax similar to Haskell do-notation and State monad.","keywords":[{"label":"ruby,haskell,do-notation,metaprogramming","value":"ruby,haskell,do-notation,metaprogramming"}],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-6385f5b1c1922","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"locations":{"business":{"name":"","businessType":"","image":"","areaServed":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"streetLine1":"","streetLine2":"","zipCode":"","city":"","state":"","country":"","addressFormat":"#streetLineOne\n#streetLineTwo\n#city, #state #zipCode"},"contact":{"email":"","phone":"","phoneFormatted":"","fax":"","faxFormatted":""},"ids":{"vat":"","tax":"","chamberOfCommerce":""},"payment":{"priceRange":"","currenciesAccepted":"","methods":""}}},"openingHours":{"useDefaults":true,"show":true,"alwaysOpen":false,"use24hFormat":false,"timezone":"","labels":{"closed":"","alwaysOpen":""},"days":{"monday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"tuesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"wednesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"thursday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"friday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"saturday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"sunday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"}}}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-04 12:44:30","updated":"2025-09-26 11:21:39","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\/category\/development\/\" title=\"Engineering\">Engineering<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tChainFlow \u2013 refactor your data processing\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/railsware.com\/blog"},{"label":"Engineering","link":"https:\/\/railsware.com\/blog\/category\/development\/"},{"label":"ChainFlow &#8211; refactor your data processing","link":"https:\/\/railsware.com\/blog\/chainflow-refactor-your-data-processing\/"}],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/ChainFlow.png","article_background":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/6899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=6899"}],"version-history":[{"count":24,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/6899\/revisions"}],"predecessor-version":[{"id":14125,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/6899\/revisions\/14125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/9436"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=6899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=6899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=6899"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=6899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}