Class: Optics::IxLens
Instance Method Summary collapse
-
#initialize(index) ⇒ IxLens
constructor
A new instance of IxLens.
Methods inherited from Lens
Constructor Details
#initialize(index) ⇒ IxLens
Returns a new instance of IxLens.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/optics.rb', line 38 def initialize(index) super( -> (subject) { subject[index] }, -> (subject, new_value) { subject.each_with_index.map { |old_value, value_index| value_index == index ? new_value : old_value } } ) end |