Class: Lite::Validation::Validator::Option::Some::Complex::Wrappers::Array

Inherits:
Abstract::Iterable
  • Object
show all
Includes:
Singular
Defined in:
lib/lite/validation/validator/option/some/complex/wrappers/array.rb

Instance Method Summary collapse

Methods included from Singular

#some_or_nil, #to_option, #unwrap

Methods included from Dig

#dig

Instance Method Details

#fetch(index) ⇒ Object

Raises:

  • (InvalidAccess)


16
17
18
19
20
21
# File 'lib/lite/validation/validator/option/some/complex/wrappers/array.rb', line 16

def fetch(index)
  raise InvalidAccess, "Invalid index to array: #{index}" unless index.is_a?(Integer)
  return Option.none unless (0...value.length).include?(index)

  Option.some(value[index])
end

#inspectObject



29
30
31
# File 'lib/lite/validation/validator/option/some/complex/wrappers/array.rb', line 29

def inspect
  "#<Option::Some::Array length=#{value.length}>"
end

#reduce(initial_state, &block) ⇒ Object



23
24
25
26
27
# File 'lib/lite/validation/validator/option/some/complex/wrappers/array.rb', line 23

def reduce(initial_state, &block)
  value.lazy
       .each_with_index
       .reduce(initial_state, &block)
end