lib/berkeley_library/util/arrays.rb
# Given a block or a value, finds the index of the first matching value
# at or after the specified start index.
#
# @overload find_index(value, in_array:, start_index:)
#   Finds the first index of the specified value.
#   @param value [Object] the value to find
#   @param in_array [Array] the array to search
#   @param start_index [Integer] the index to start with
#   @return [Integer, nil] the index, or `nil` if no value matches
# @overload find_index(&block)
#   Finds the index of the first value matching
#   the specified block.
#   @param in_array [Array] the array to search
#   @param start_index [Integer] the index to start with
#   @yieldreturn [Boolean] whether the element matches
#   @return [Integer, nil] the index, or `nil` if no value matches
# @overload find_index
#   @param in_array [Array] the array to search
#   @param start_index [Integer] the index to start with
#   @return [Enumerator] a new enumerator
Given a block or a value, finds the index of the first matching value
at or after the specified start index.
Given a block or a value finds the index of the first matching value at or after the specified start index .
def find_index(*args, in_array:, start_index: 0, &block)
        raise ArgumentError, "wrong number of arguments (given #{value.length}, expected 0..1" if args.size > 1
        return Enumerator.new { |y| find_index(in_array: in_array, start_index: start_index, &y) } if args.empty? && !block_given?
        return unless (relative_index = in_array[start_index..].find_index(*args, &block))
        relative_index + start_index
      end
def find_index ( * args , in_array : , start_index : 0 , & block ) raise ArgumentError , "wrong number of arguments (given #{value.length}, expected 0..1" if args . size > 1 return Enumerator . new { | y | find_index ( in_array : in_array , start_index : start_index , & y ) } if args . empty? && ! block_given? return unless ( relative_index = in_array [ start_index .. ] . find_index ( * args , & block ) ) relative_index + start_index end
Given a block or a value, finds the index of the first matching value
at or after the specified start index.
Given a block or a value finds the index of the first matching value at or after the specified start index .
args
<not_specific>
in_array
<not_specific>
start_index
<not_specific>
block
<not_specific>
overload
find_index(value, in_array:, start_index:) Finds the first index of the specified value. @param value [Object] the value to find @param in_array [Array] the array to search @param start_index [Integer] the index to start with @return [Integer, nil] the index, or `nil` if no value matches
find_index ( value in_array : start_index : ) Finds the first index of the specified value . @param value [ Object ] the value to find @param in_array [ Array ] the array to search @param start_index [ Integer ] the index to start with @return [ Integer nil ] the index or ` nil ` if no value matches
overload
find_index(█) Finds the index of the first value matching the specified block. @param in_array [Array] the array to search @param start_index [Integer] the index to start with @yieldreturn [Boolean] whether the element matches @return [Integer, nil] the index, or `nil` if no value matches
find_index ( █ ) Finds the index of the first value matching the specified block . @param in_array [ Array ] the array to search @param start_index [ Integer ] the index to start with @yieldreturn [ Boolean ] whether the element matches @return [ Integer nil ] the index or ` nil ` if no value matches
overload
find_index @param in_array [Array] the array to search @param start_index [Integer] the index to start with @return [Enumerator] a new enumerator
find_index @param in_array [ Array ] the array to search @param start_index [ Integer ] the index to start with @return [ Enumerator ] a new enumerator