Class: Accessory::Accessors::AllAccessor
- Inherits:
-
Accessory::Accessor
- Object
- Accessory::Accessor
- Accessory::Accessors::AllAccessor
- Defined in:
- lib/accessory/accessors/all_accessor.rb
Overview
Traverses all elements of an Enumerable.
Aliases
-
Accessory::Access::FluentHelpers#all (included in Lens and BoundLens)
Equivalents in Elixir’s Access module
Default constructor used by predecessor accessor
-
Array.new
Instance Method Summary collapse
-
#get(data, &succ) ⇒ Array
Feeds each element of
datadown the accessor chain, and returns the results. -
#get_and_update(data) ⇒ Array
Feeds each element of
datadown the accessor chain, overwritingdatawith the results.
Methods inherited from Accessory::Accessor
#traverse, #traverse_or_default
Instance Method Details
#get(data, &succ) ⇒ Array
Feeds each element of data down the accessor chain, and returns the results.
35 36 37 38 39 40 41 |
# 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) ⇒ Array
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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/accessory/accessors/all_accessor.rb', line 50 def get_and_update(data) results = [] new_data = [] (data || []).each do |pos| case yield(pos) in [result, new_value] results.push(result) new_data.push(new_value) in :pop results.push(pos) end end [results, new_data] end |