[#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:106422] Re: [Ruby master Feature#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" }
From:
Brandon Weaver <keystonelemur@...>
Date:
2021-12-02 22:29:21 UTC
List:
ruby-core #106422
You know, it would be lovely to have a method like that that takes a
pattern matching stanza and produces something which responds to ===. That
would be a fairly elegant solution to the above question with more
flexibility in other parts of applications.
On Thu, Dec 2, 2021, 11:41 AM zverok (Victor Shepelev) <
noreply@ruby-lang.org> wrote:
> Issue #18369 has been updated by zverok (Victor Shepelev).
>
>
> > it would be nice to have syntax that allows to shorten one-line matchers
> for predicates where they would be commonly used
>
> TBH, since pattern matching inception I hope for some way of putting
> patterns into values窶杯o store them in constants, and, in that case, simple
> `grep` will do (if that value would respond to `#===` which it should!):
> ```ruby
> MY_PATTERN = _pm_(first_name: /^J/, age: 18..)
>
> # ...and then
> if value in MY_PATTERN ...
>
> # ...and, consequently,
> people.grep(_pm_(first_name: /^J/, age: 18..))
> ```
> (I am marking the dreamed-of PM constructor as ugly `_pm_` here to
> underline it is not a ready proposal, but "something should be here")
>
> ----------------------------------------
> Feature #18369: users.detect(:name, "Dorian") as shorthand for
> users.detect { |user| user.name == "Dorian" }
> https://bugs.ruby-lang.org/issues/18369#change-95052
>
> * 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>
>
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>