[#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:106405] [Ruby master Feature#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" }
From:
"baweaver (Brandon Weaver)" <noreply@...>
Date:
2021-12-02 17:58:08 UTC
List:
ruby-core #106405
Issue #18369 has been updated by baweaver (Brandon Weaver).
Pattern Matching may make a very interesting tie-in here for a short-hand:
```ruby
# Struct provides built-in pattern matching abilities
Person = Struct.new(:first_name, :last_name, :age)
jim = Person.new("Jim", "Smith", 30)
jill = Person.new("Jill", "Smith", 20)
sue = Person.new("Sue", "Smith", 40)
people = [jim, jill, sue]
# Currently works
people.select { _1 in { first_name: /^J/, age: 18.. } }
# Potential 1: bare keywords
people.select { _1 in first_name: /^J/, age: 18.. }
# Potential 2: `in` shorthand
people.select(&in first_name: /^J/, age: 18..)
```
Generally I think 1 is doable, 2 is stretching, though it would be nice to have syntax that allows to shorten one-line matchers for predicates where they would be commonly used.
----------------------------------------
Feature #18369: users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" }
https://bugs.ruby-lang.org/issues/18369#change-95043
* 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>