ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: zverok.offline@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:92876] [Ruby trunk Feature#15799] pipeline operator
Date: Tue, 28 May 2019 11:41:43 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-78255.20190528114143.645fcb114f436741@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15799.20190427083121@ruby-lang.org

Issue #15799 has been updated by zverok (Victor Shepelev).


```ruby
1.. |> take 10 |> map {|x| x*2} |> (x)
```

I believe that the ONLY sane reason for the new operator is ending the long chain with "...and now, put it into variable". The rest is total mistery, however you look at it, e.g. why not 
```ruby
(1..).take(10).map {|x| x*2}
```
...that's perfectly readable and usual Ruby, why rip the Elixir? 

> As a side note, I became less wanting for the feature "...and not put it into variable" since introduction of `then`, because you always can 
```ruby
(1..).take(10).map {|x| x*2}
  .then { |res| 
     #...work with the result
  }
```

But **if** "...and now put it into a variable" is necessary, why not reuse `=>`? It is invalid syntax currently (without braces), and would be consistent with `rescue Foo => x` and the same use in a new pattern-matching.

So the result would be
```ruby
(1..).take(10).map {|x| x*2} => x
```

----------------------------------------
Feature #15799: pipeline operator
https://bugs.ruby-lang.org/issues/15799#change-78255

* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Implemented the pipeline operator `|>`, a topic of "ruby committers vs the world" in RubyKaigi 2019.
Also a casual idea of rightward assignment.

```ruby
1.. |> take 10 |> map {|x| x*2} |> (x)
p x #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
```

https://github.com/nobu/ruby/tree/feature/pipeline




-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2019-05-28 11:41 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15799.20190427083121@ruby-lang.org>
2019-04-27  8:31 ` [ruby-core:92432] [Ruby trunk Feature#15799] pipeline operator nobu
2019-04-27 10:28 ` [ruby-core:92433] " duerst
2019-04-27 13:23 ` [ruby-core:92436] " eregontp
2019-04-27 14:19 ` [ruby-core:92438] " shevegen
2019-04-28  1:26 ` [ruby-core:92453] " nobu
2019-05-01  1:53 ` [ruby-core:92506] " duerst
2019-05-19 22:05 ` [ruby-core:92725] " jonathan
2019-05-25  1:28 ` [ruby-core:92838] " merch-redmine
2019-05-28  4:54 ` [ruby-core:92869] " konsolebox
2019-05-28  7:37 ` [ruby-core:92872] " konsolebox
2019-05-28  9:33 ` [ruby-core:92873] " matthew
2019-05-28 11:41 ` zverok.offline [this message]
2019-05-28 13:45 ` [ruby-core:92877] " konsolebox
2019-06-12  6:36 ` [ruby-core:93060] " nobu
2019-06-12 13:35 ` [ruby-core:93073] " zverok.offline
2019-06-13 10:00 ` [ruby-core:93103] " eregontp
2019-06-13 11:43 ` [ruby-core:93105] " shevegen
2019-06-13 13:23 ` [ruby-core:93110] " dgutov
2019-06-13 14:09 ` [ruby-core:93111] " ttilberg
2019-06-14  0:12 ` [ruby-core:93118] " chris
2019-06-14  2:01 ` [ruby-core:93120] " joshua.goodall
2019-06-14  2:51 ` [ruby-core:93122] " keystonelemur
2019-06-14  3:00 ` [ruby-core:93125] " matz
2019-06-14  3:18 ` [ruby-core:93127] " merch-redmine
2019-06-14  5:42 ` [ruby-core:93129] " chris
2019-06-14  6:15 ` [ruby-core:93130] " keystonelemur
2019-06-14  7:45 ` [ruby-core:93133] " matz
2019-06-14  8:28 ` [ruby-core:93134] " keystonelemur
2019-06-14 10:30 ` [ruby-core:93135] " mail
2019-06-14 11:03 ` [ruby-core:93137] " rogeriocfj
2019-06-14 13:15 ` [ruby-core:93141] " cichol
2019-06-14 16:56 ` [ruby-core:93144] " sean.m.huber
2019-06-14 19:30 ` [ruby-core:93145] " konsolebox
2019-06-14 23:12 ` [ruby-core:93149] " dgutov
2019-06-16  0:17 ` [ruby-core:93167] " mame
2019-06-16  0:49 ` [ruby-core:93168] " samuel
2019-06-16  8:11 ` [ruby-core:93175] " josh.cheek
2019-06-16 15:29 ` [ruby-core:93188] " shannonskipper
2019-06-30  9:52 ` [ruby-core:93424] " eregontp
2019-06-30 10:19 ` [ruby-core:93425] " eregontp
2019-06-30 10:38 ` [ruby-core:93426] " eregontp
2019-06-30 11:53 ` [ruby-core:93428] " eregontp
2019-08-29  5:39 ` [ruby-core:94645] [Ruby master " matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-78255.20190528114143.645fcb114f436741@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).