[#90865] [Ruby trunk Bug#15499] Breaking behavior on ruby 2.6: rb_thread_call_without_gvl doesn't invoke unblock_function when used on the main thread — apolcyn@...
Issue #15499 has been reported by apolcyn (alex polcyn).
3 messages
2019/01/03
[#90877] [Ruby trunk Bug#15499] Breaking behavior on ruby 2.6: rb_thread_call_without_gvl doesn't invoke unblock_function when used on the main thread — apolcyn@...
Issue #15499 has been updated by apolcyn (alex polcyn).
3 messages
2019/01/03
[#90895] Re: [ruby-alerts:11680] failure alert on trunk-mjit@silicon-docker (NG (r66707)) — Eric Wong <normalperson@...>
ko1c-failure@atdot.net wrote:
4 messages
2019/01/05
[#90896] Re: [ruby-alerts:11680] failure alert on trunk-mjit@silicon-docker (NG (r66707))
— Takashi Kokubun <takashikkbn@...>
2019/01/05
Thanks to explain that.
[#91200] [Ruby trunk Feature#15553] Addrinfo.getaddrinfo supports timeout — glass.saga@...
Issue #15553 has been reported by Glass_saga (Masaki Matsushita).
4 messages
2019/01/21
[#91289] Re: [Ruby trunk Feature#15553] Addrinfo.getaddrinfo supports timeout
— Eric Wong <normalperson@...>
2019/01/26
glass.saga@gmail.com wrote:
[ruby-core:91300] [Ruby trunk Feature#15557] A new class that stores a condition and the previous receiver
From:
nobu@...
Date:
2019-01-27 05:22:13 UTC
List:
ruby-core #91300
Issue #15557 has been updated by nobu (Nobuyoshi Nakada).
zverok (Victor Shepelev) wrote:
> > `Enumerable#grep`
>
> Well, it is not "it accepts callable", it is a part of "it accepts any pattern (including Proc)", and passing Proc into `grep` makes sense only in "polymorphic pattern situation" (we have a pattern variable, which can be Proc, or Regexp, or Range)... I mean, nobody probably writes just
> ```ruby
> something.grep(->(x) { x.odd? })
> ```
I meant an example of condition and processing by one method.
```ruby
something.grep(->(x) { x.odd? }) {|x| do_odd_thing(x)}
```
> ...because they write
> ```ruby
> something.select(&:odd?)
> ```
`Enumerable#select` with a block needs chained methods.
----------------------------------------
Feature #15557: A new class that stores a condition and the previous receiver
https://bugs.ruby-lang.org/issues/15557#change-76546
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I often see code like this:
```ruby
foo = default_definition
foo = some_method(foo) if some_condition(foo)
foo = another_method(foo) if another_condition(foo)
...
```
It would be nice if we can write this as a method chain. Since we now have the method `then`, I thought it would be a nice fit to introduce a method called `when`, such that putting it right in front of `then` would execute the `then` method as ordinarily only when the condition is satisfied, and returns the previous receiver otherwise so that the code above can be rewritten as:
```ruby
foo =
default_definition
.when{|foo| some_condition(foo)}
.then{|foo| some_method(foo)}
.when{|foo| another_condition(foo)}
.then{|foo| another_method(foo)}
```
This proposal is also a generalization of what I intended to cover by https://bugs.ruby-lang.org/issues/13807. That is,
```ruby
a.some_condition ? a : b
```
would rewritten as:
```ruby
a.when(&:some_condition).then{b}
```
The proposal can be implemented by introducing a class called `Condition`, which stores a condition and the previous receiver, and works with `then` in a particular way.
```ruby
class Object
def when
Condition.new(self, yield(self))
end
end
class Condition
def initialize default, condition
@default, @condition = default, condition
end
def then
@condition ? yield(@default) : @default
end
end
```
And additionally, if we introduce a negated method `unless` (or `else`) as follows:
```ruby
class Object
def unless
Condition.new(self, !yield(self))
end
end
```
then we can use that for purposes such as validation of a variable as follows:
```ruby
bar =
gets
.unless{|bar| some_validation(bar)}
.then{raise "The input is bad."}
.unless{|bar| another_validation(bar)}
.then{raise "The input is bad in another way."}
```
--
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>