class Dry::Types::Array::Member
def try(input, &block) # rubocop:disable Metrics/PerceivedComplexity
- Api: - public
Returns:
-
(Result, Logic::Result)
-
Other tags:
- Yieldreturn: -
Other tags:
- Yieldparam: failure -
Parameters:
-
block
(#call, nil
) -- -
input
(Array, Object
) --
def try(input, &block) # rubocop:disable Metrics/PerceivedComplexity if primitive?(input) output = [] result = input.map { |el| member.try(el) } result.each do |r| output << r.input unless Undefined.equal?(r.input) end if result.all?(&:success?) success(output) else error = result.find(&:failure?).error failure = failure(output, error) block ? yield(failure) : failure end else failure = failure(input, CoercionError.new("#{input} is not an array")) block ? yield(failure) : failure end end