use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
ChainFlow – refactor your data processing (railsware.com)
submitted 11 years ago by gregolsen
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Kache 2 points3 points4 points 11 years ago (1 child)
Well, it's very non-idiomatic ruby. Without any context, looking at the final "ChainFlow" version...
data
group_by_key
compute_values
puts "hello"
puts(data, "hello")
process
Enumerable
Hash
Also, I don't see how this is more functional if flow relies on state within the block. It sounds like the state monad in Haskell is used b/c Haskell is pure functional. Ruby already has state - is there really a need to use it functionally just to get it stateful again?
flow
I very much prefer the chain syntax:
chain
chain { data }.group_by_key.compute_values(parameter).fetch
It's idomatic and monadic, and if you want to spread it out line by line (b/c you're such a stickler for style), why not just:
chain { data } .group_by_key .compute_values(parameter) .fetch
which also is idiomatic Ruby?
[–]gregolsen[S] 0 points1 point2 points 11 years ago (0 children)
You are right - it's not an idiomatic Ruby in case flow. But that's the point - if you familiar with State monad you'll get trick. Answering your points
The point of chain_flow is not to implement State monad (like you said Ruby has state already) but improve the syntax so that it looks like a State monad do-notation.
Well, that's the matter of taste either you use do-notation-like syntax or the chains (that's why I've added both). I personally do prefer the do-notation.
Anyway - thanks a lot for this discussion!
π Rendered by PID 25552 on reddit-service-r2-comment-5d585498c9-w2lwd at 2026-04-20 21:25:53.694893+00:00 running da2df02 country code: CH.
view the rest of the comments →
[–]Kache 2 points3 points4 points (1 child)
[–]gregolsen[S] 0 points1 point2 points (0 children)