lib/berkeley_library/util/arrays.rb
# Counts how many contiguous elements from the start of an
# sequence of values satisfy the given block.
#
# @overload count_while(arr:)
#   Returns an enumerator.
#   @param values [Enumerable] the values
#   @return [Enumerator] the enumerator.
# @overload count_while(arr:, &block)
#   Passes elements to the block until the block returns nil or false,
#   then stops iterating and returns the count of matching elements.
#   @param values [Enumerable] the values
#   @return [Integer] the count
Counts how many contiguous elements from the start of an
sequence of values satisfy the given block.
Counts how many contiguous elements from the start of an sequence of values satisfy the given block .
def count_while(values:)
        return to_enum(:count_while, values: values) unless block_given?
        values.inject(0) do |count, x|
          matched = yield x
          break count unless matched
          count + 1
        end
      end
def count_while ( values : ) return to_enum ( :count_while , values : values ) unless block_given? values . inject ( 0 ) do | count , x | matched = yield x break count unless matched count + 1 end end
Counts how many contiguous elements from the start of an
sequence of values satisfy the given block.
Counts how many contiguous elements from the start of an sequence of values satisfy the given block .
values
<not_specific>
overload
) Returns an enumerator. @param values [Enumerable] the values @return [Enumerator] the enumerator.
) Returns an enumerator . @param values [ Enumerable ] the values @return [ Enumerator ] the enumerator .
overload
, █) Passes elements to the block until the block returns nil or false, then stops iterating and returns the count of matching elements. @param values [Enumerable] the values @return [Integer] the count
█ ) Passes elements to the block until the block returns nil or false then stops iterating and returns the count of matching elements . @param values [ Enumerable ] the values @return [ Integer ] the count