def bsearch
      return enum_for(:bsearch) if not block_given?
      low, high, result = 0, @size, nil
      while low < high
        mid = (low + ((high - low) >> 1))
        val = get(mid)
        v   = yield val
        if v.is_a? Numeric
          if v == 0
            return val
          elsif v > 0
            high = mid
          else
            low = mid + 1
          end
        elsif v == true
          result = val
          high = mid
        elsif !v
          low = mid + 1
        else
          raise TypeError, "wrong argument type #{v.class} (must be numeric, true, false, or nil)"
        end
      end
      return result
    end
def bsearch
      return enum_for(:bsearch) if not block_given?
      low, high, result = 0, @size, nil
      while low < high
        mid = (low + ((high - low) >> 1))
        val = get(mid)
        v   = yield val
        if v.is_a? Numeric
          if v == 0
            return val
          elsif v > 0
            high = mid
          else
            low = mid + 1
          end
        elsif v == true
          result = val
          high = mid
        elsif !v
          low = mid + 1
        else
          raise TypeError, "wrong argument type #{v.class} (must be numeric, true, false, or nil)"
        end
      end
      return result
    end
Finds a value from this `Tuple` which meets the condition defined by the
 provided block, using a binary search. The tuple must already be sorted
 with respect to the block.  See Ruby's `Array#bsearch` for details,
 behaviour is equivalent.

 @example
   t = Erlang::Tuple[1, 3, 5, 7, 9, 11, 13]
   # Block returns true/false for exact element match:
   t.bsearch { |e| e > 4 }      # => 5
   # Block returns number to match an element in 4 <= e <= 7:
   t.bsearch { |e| 1 - e / 4 }  # => 7

 @yield Once for at most `log n` elements, where `n` is the size of the
        tuple. The exact elements and ordering are undefined.
 @yieldreturn [Boolean] `true` if this element matches the criteria, `false` otherwise.
 @yieldreturn [Integer] See `Array#bsearch` for details.
 @yieldparam [Object] element element to be evaluated
 @return [Object] The matched element, or `nil` if none found.
 @raise TypeError if the block returns a non-numeric, non-boolean, non-nil
                  value.