TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Elixir-style pipelines in Ruby

63 pointsby gregnavisover 2 years ago

6 comments

bwilliamsover 2 years ago
The beauty (and horror) of Ruby is that you can do almost anything with it. I think this is a really interesting and clever use of the &quot;can do anything&quot; aspect of Ruby, although I think I&#x27;d prefer not to run into it in a production app.<p>Still, it&#x27;s really cool to see how far we can push&#x2F;mold the language to accomplish different tasks and patterns.
joeman1000over 2 years ago
I&#x27;ve had a look at threading&#x2F;piping operators in a few languages (list below). I&#x27;d say that Racket has the best one I&#x27;ve used. I love that you can specify a &#x27;_&#x27; for the hole which the result from the previous operation will fill. Julia&#x27;s threading macro is surprisingly brittle, only letting you chain single-argument functions unless you want to use anonymous functions with one bound variable and the rest free.<p>+ Haskell :: <a href="https:&#x2F;&#x2F;www.schoolofhaskell.com&#x2F;user&#x2F;Gabriel439&#x2F;Pipes%20tutorial" rel="nofollow">https:&#x2F;&#x2F;www.schoolofhaskell.com&#x2F;user&#x2F;Gabriel439&#x2F;Pipes%20tuto...</a><p>+ Racket :: <a href="https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;threading&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;docs.racket-lang.org&#x2F;threading&#x2F;index.html</a><p>+ Clojure :: <a href="https:&#x2F;&#x2F;clojure.org&#x2F;guides&#x2F;threading_macros" rel="nofollow">https:&#x2F;&#x2F;clojure.org&#x2F;guides&#x2F;threading_macros</a><p>+ Julia :: <a href="https:&#x2F;&#x2F;syl1.gitbook.io&#x2F;julia-language-a-concise-tutorial&#x2F;useful-packages&#x2F;pipe" rel="nofollow">https:&#x2F;&#x2F;syl1.gitbook.io&#x2F;julia-language-a-concise-tutorial&#x2F;us...</a><p>+ R :: <a href="https:&#x2F;&#x2F;r4ds.had.co.nz&#x2F;pipes.html" rel="nofollow">https:&#x2F;&#x2F;r4ds.had.co.nz&#x2F;pipes.html</a>
评论 #33940492 未加载
评论 #33937914 未加载
评论 #33943114 未加载
bonquesha99over 2 years ago
Check out this proof of concept gem to perform pipe operations in Ruby using block expressions:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;lendinghome&#x2F;pipe_operator#-pipe_operator" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lendinghome&#x2F;pipe_operator#-pipe_operator</a><p><pre><code> &quot;https:&#x2F;&#x2F;api.github.com&#x2F;repos&#x2F;ruby&#x2F;ruby&quot;.pipe do URI.parse Net::HTTP.get JSON.parse.fetch(&quot;stargazers_count&quot;) yield_self { |n| &quot;Ruby has #{n} stars&quot; } Kernel.puts end #=&gt; Ruby has 15120 stars</code></pre>
quechimbaover 2 years ago
I like using .then for chaining stuff, like this:<p><pre><code> sig { params(obj: T.untyped).void } def write(obj) obj .then { Array(_1) } .then { @wrapper.pack(_1) } .then { @deflate.deflate(_1, Zlib::SYNC_FLUSH) } .then { @body.write(_1) } end</code></pre>
ilyashover 2 years ago
While not as thorough solution as mentioned here in comments, UFCS goes a long way in this direction. In Next Generation Shell, I&#x27;ve designed the methods so that the first parameter is something that is likely to come from &quot;the pipeline&quot;. Hence mylist.filter(...).map(...) just work. Combined with multiple dispatch and the fact that methods don&#x27;t belong to a particular type&#x2F;class, it allows creating user-defined methods with same convention to work with any existing and new types&#x2F;classes.<p>UFCS - <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Uniform_Function_Call_Syntax" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Uniform_Function_Call_Syntax</a>
zelphirkaltover 2 years ago
Do the steps of the pipeline implementation in Ruby run concurrently?<p>I once did an Elixir course and really liked the pipelines. I continued implementing pipelines with a Scheme macro, but not concurrently.
评论 #33935147 未加载
评论 #33935272 未加载