Bug #7725

bsearch should return enumerator when called without a block

Added by Marc-Andre Lafortune over 2 years ago. Updated about 2 years ago.

[ruby-core:51564]
Status:Closed
Priority:Normal
Assignee:Marc-Andre Lafortune
ruby -v:r38825 Backport:

Description

bsearch should return enumerator when called without a block

This would allow, for example

values.bsearch.with_index{|val, index| val >= some_array[index]} # => a value

Otherwise, one must use zip/each_with_index and will get an array returned, not just the value seeked:

r = values.zip(some_array).bsearch{|val, other_val| val >= other_val}
a_value = r.first

Associated revisions

Revision 38984
Added by Marc-Andre Lafortune about 2 years ago

  • array.c (rb_ary_bsearch): Return enumerator if no block [#7725]

  • range.c (range_bsearch): ditto

  • test/ruby/test_array.rb: Test for above

  • test/ruby/test_range.rb: ditto

Revision 38984
Added by Marc-Andre Lafortune about 2 years ago

  • array.c (rb_ary_bsearch): Return enumerator if no block [#7725]

  • range.c (range_bsearch): ditto

  • test/ruby/test_array.rb: Test for above

  • test/ruby/test_range.rb: ditto

History

#1 Updated by Marc-Andre Lafortune about 2 years ago

  • Status changed from Open to Closed
  • Assignee set to Marc-Andre Lafortune

Fixed with r38984.

Also available in: Atom PDF