class Remap::Path::Input

Returns the value at a given path

@example Select “A” from { a: { b: { c: [“A”] } } }

state = Remap::State.call({ a: { b: { c: ["A"] } } })
first = Remap::Selector::Index.new(index: 0)
path = Remap::Path::Input.new([:a, :b, :c, first])

path.call(state) do |state|
  state.fetch(:value)
end

Private Instance Methods

call(state, &iterator) click to toggle source

@param state [State]

@yieldparam [State] @yieldreturn [State]

@return [State]

# File lib/remap/path/input.rb, line 27
def call(state, &iterator)
  unless iterator
    raise ArgumentError, "Input path requires an iterator block"
  end

  selectors.reverse.reduce(iterator) do |inner_iterator, selector|
    -> inner_state { selector.call(inner_state, &inner_iterator) }
  end.call(state)
end