ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: keystonelemur@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:93130] [Ruby trunk Feature#15799] pipeline operator
Date: Fri, 14 Jun 2019 06:15:57 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-78559.20190614061556.cb31c3e35d8dcaf1@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15799.20190427083121@ruby-lang.org

Issue #15799 has been updated by baweaver (Brandon Weaver).


That's a very fair point @jeremyevans0, it would introduce two lookup chains even under the most ideal of circumstances. Perhaps if `&` were slightly extended, one could do this:

```ruby
def double(n) n * 2 end

increment = -> n { n + 1 }

5
|> &double
|> &increment
|> to_s(2)
|> reverse
|> to_i
```

...wherein `&` would retain its meaning of coercing something to a proc, make the call chain more explicit, and kill the speed hit potential.

The downside is it would add a feature to `&` that it could convert a method to a proc which does not currently exist and would do all types of interesting things to the interpreter for parens. It had been mentioned in the past to have anonymous or self-oriented `.:` to get around this:

```ruby
5
|> &.:double
|> &increment
|> to_s(2)
|> reverse
|> to_i
```

Though that presents issues of 2+ arity functions. It's certainly a hard issue to solve for, but if a solution can be found it would be extremely powerful for the language.

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

* Author: nobu (Nobuyoshi Nakada)
* Status: Closed
* 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 {|e| e*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-06-14  6:16 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 ` [ruby-core:92876] " zverok.offline
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 ` keystonelemur [this message]
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-78559.20190614061556.cb31c3e35d8dcaf1@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).