class Morpher::Transform::Array

Transform an array via mapping it over transform

Constants

MESSAGE
PRIMITIVE

Public Instance Methods

call(input) click to toggle source

Apply transformation to input

@param [Object] input

@return [Either<Error, Array<Object>>]

# File lib/morpher/transform.rb, line 277
def call(input)
  PRIMITIVE
    .call(input)
    .lmap(&method(:lift_error))
    .bind(&method(:run))
end

Private Instance Methods

run(input) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/morpher/transform.rb, line 287
def run(input)
  output = []

  input.each_with_index do |value, index|
    output << transform.call(value).lmap do |error|
      return failure(
        error(
          cause:   Index.wrap(error, index),
          message: MESSAGE % { index: index },
          input:   input
        )
      )
    end.from_right
  end

  success(output)
end