Bug #7725

bsearch should return enumerator when called without a block

Added by Marc-Andre Lafortune over 1 year ago. Updated about 1 year ago.

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

Description

bsearch should return enumerator when called without a block

This would allow, for example

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

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

r = values.zip(somearray).bsearch{|val, otherval| val >= otherval}
a
value = r.first

Associated revisions

Revision 38984
Added by Marc-Andre Lafortune about 1 year ago

  • array.c (rbarybsearch): 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 1 year ago

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

Fixed with r38984.

Also available in: Atom PDF