[#106355] [Ruby master Bug#18373] RBS build failure: '/include/x86_64-linux/ruby/config.h', needed by 'constants.o'. — "vo.x (Vit Ondruch)" <noreply@...>
Issue #18373 has been reported by vo.x (Vit Ondruch).
28 messages
2021/12/01
[ruby-core:106391] [Ruby master Feature#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" }
From:
"cvss (Kirill Vechera)" <noreply@...>
Date:
2021-12-02 13:52:03 UTC
List:
ruby-core #106391
Issue #18369 has been updated by cvss (Kirill Vechera).
It's a good occasion to use the composition of Proc/Method objects:
``` ruby
collection.detect(&:first_name.to_proc>>"Dorian".method(:==))
```
If we had a shorthand operator for Object#method (#12125), it would look nicer:
``` ruby
collection.detect(:first_name.to_proc >> "Dorian".:==)
```
And if we make a shorthand `Symbol#>>` for the composition of a Symbol and a Proc, it would look even wonderful:
``` ruby
class Symbol
def >> b
to_proc >> b
end
end
collection.detect(&:first_name>>"Dorian".:==)
```
When you are frequently using such constructions you can read it easily, but it is definitely more confusing comparing to the plain variant
``` ruby
collection.detect{_1.first_name == "Dorian"}
```
----------------------------------------
Feature #18369: users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" }
https://bugs.ruby-lang.org/issues/18369#change-95029
* Author: dorianmariefr (Dorian Mari辿)
* Status: Open
* Priority: Normal
----------------------------------------
Hi,
I was thinking I often do things like `collection.detect { |item| item.attribute == value }` and a shorthand like `collection.detect(:attribute, value)` would be quite useful
What do you think?
And I know there is `collection.detect { _1.attribute == value }` but I try not to use `_1` and this syntax would be shorter and simpler
Could also apply to other methods like `all?` (`collection.all?(:attribute, value)`), and basically any Enumerable method https://rubydoc.info/stdlib/core/Enumerable
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>