class Remap::Mapper::And

Represents two mappers that are combined with the & operator

@example Combine two mappers

class Mapper1 < Remap::Base
  contract do
    required(:a1)
  end
end

class Mapper2 < Remap::Base
  contract do
    required(:a2)
  end
end

state = Remap::State.call({ a2: 2, a1: 1 })
output = (Mapper1 & Mapper2).call!(state)
output.fetch(:value) # => { a2: 2, a1: 1 }

Public Instance Methods

call!(state, &error) click to toggle source

Succeeds if both left and right succeed Returns the combined result of left and right

@param state [State]

@yield [Failure] if mapper fails

@return [Result]

# File lib/remap/mapper/and.rb, line 34
def call!(state, &error)
  state1 = left.call!(state) do |failure1|
    right.call!(state) do |failure2|
      return error[failure1.merge(failure2)]
    end

    return error[failure1]
  end

  state2 = right.call!(state) do |failure|
    return error[failure]
  end

  state1.combine(state2)
end
inspect() click to toggle source

@return [String]

# File lib/remap/mapper/and.rb, line 51
def inspect
  "%s & %s" % [left, right]
end
Also aliased as: to_s
to_s()
Alias for: inspect