Class: Remap::Selector::All

Inherits:
Concrete
  • Object
show all
Defined in:
lib/remap/selector/all.rb

Overview

Selects all elements from a state

Examples:

Select all keys from array hash

state = Remap::State.call([{a: "A1"}, {a: "A2"}])
all = Remap::Selector::All.new
result = all.call(state) do |other_state|
  value = other_state.fetch(:value).class
  other_state.merge(value: value)
end
result.fetch(:value) # => [Hash, Hash]

Instance Method Summary collapse

Instance Method Details

#call(outer_state) {|| ... } ⇒ State<U>

Iterates over state and passes each value to block

Parameters:

  • outer_state (State<Enumerable<T>>)

Yield Parameters:

Yield Returns:

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/remap/selector/all.rb', line 28

def call(outer_state, &block)
  unless block_given?
    raise ArgumentError, "All selector requires an iteration block"
  end

  outer_state.bind(quantifier: "*") do |enum, state|
    requirement[enum] do
      state.fatal!("Expected enumeration but got %p (%s)", enum, enum.class)
    end

    state.map(&block)
  end
end