[ruby-core:84384] [Ruby trunk Feature#12318] Returning the evaluated value of a block

From: andrew@...
Date: 2017-12-21 06:15:12 UTC
List: ruby-core #84384
Issue #12318 has been updated by avit (Andrew Vit).


This is now implemented as `yield_self`

Close please?

----------------------------------------
Feature #12318: Returning the evaluated value of a block
https://bugs.ruby-lang.org/issues/12318#change-68575

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often achieve an element using an iterator with a block, and then apply the same/a similar block to the element I get. Examples are:

~~~ruby
[7, 8, 9]
.max_by{|e| e % 3}
.tap{|e| break e % 3}
# => 2

["foo", "bar", "baz"]
.find{|e| e[/(.)\1/]}
.tap{|e| break e[/(.)\1/]}
# => "oo"
~~~

I would like a method on `Enumerator` that returns the result of the block rather than the original element in the iterator. Not sure about the name, but if I call it `and_return` temporary, it should look like:

~~~ruby
[7, 8, 9]
.max_by.and_return{|e| e % 3}
# => 2

["foo", "bar", "baz"]
.find.and_return{|e| e[/(.)\1/]}
# => "oo"
~~~




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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next