class Accessory::Accessors::AllAccessor

Traverses all elements of an Enumerable.

Aliases

Equivalents in Elixir's {hexdocs.pm/elixir/Access.html Access} module

Default constructor used by predecessor accessor

Public Instance Methods

ensure_valid(traversal_result) click to toggle source

@!visibility private

# File lib/accessory/accessors/all_accessor.rb, line 20
def ensure_valid(traversal_result)
  if traversal_result.kind_of?(Enumerable)
    traversal_result
  else
    []
  end
end
get(data, &succ) click to toggle source

Feeds each element of data down the accessor chain, and returns the results. @param data [Enumerable] the Enumerable to iterate through @return [Array] the values derived from the rest of the accessor chain

# File lib/accessory/accessors/all_accessor.rb, line 35
def get(data, &succ)
  if succ
    (data || []).map(&succ)
  else
    data
  end
end
get_and_update(data) { |pos| ... } click to toggle source

Feeds each element of data down the accessor chain, overwriting data with the results.

If :pop is returned from the accessor chain, the element is dropped from the new data. @param data [Enumerable] the Enumerable to iterate through @return [Array] a two-element array containing 1. the original values found during iteration; and 2. the new data

# File lib/accessory/accessors/all_accessor.rb, line 50
def get_and_update(data)
  results = []
  new_data = []
  dirty = false

  (data || []).each do |pos|
    case yield(pos)
    in [:clean, result, _]
      results.push(result)
      new_data.push(pos)
      # ok
    in [:dirty, result, new_value]
      results.push(result)
      new_data.push(new_value)
      dirty = true
    in :pop
      results.push(pos)
      dirty = true
    end
  end

  if dirty
    [:dirty, results, new_data]
  else
    [:clean, results, data]
  end
end
inspect_args() click to toggle source

@!visibility private

# File lib/accessory/accessors/all_accessor.rb, line 29
def inspect_args; nil; end