Module: NullableOptic

Included in:
Lens
Defined in:
lib/ruby-optics/nullable.rb

Instance Method Summary collapse

Instance Method Details

#nullableObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby-optics/nullable.rb', line 4

def nullable
  self.class.new(
    -> (obj) {
      if obj.nil?
        nil
      else
        getter.(obj)
      end
    },

    -> (new_val, obj) {
      if obj.nil?
        nil
      else
        setter.(new_val, obj)
      end
    }
  )
end