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
data
down the accessor chain, and returns the results. -
#get_and_update(data) ⇒ Array
Feeds each element of
data
down the accessor chain, overwritingdata
with 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 66 67 68 69 70 71 72 73 74 75 76 |
# 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 |