Module: Optics

Defined in:
lib/ruby-optics.rb,
lib/ruby-optics/optics.rb

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.hash_lens(*keys) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/ruby-optics/optics.rb', line 8

def self.hash_lens(*keys)
  head, *tail = keys

  [build_hash_lens(head), *tail].reduce { |result_lens, key|
    result_lens.compose_lens(build_hash_lens(key))
  }
end

.indiffirent_access_hash_lens(*keys) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ruby-optics/optics.rb', line 16

def self.indiffirent_access_hash_lens(*keys)
  head, *tail = keys
  opts = { indiffirent_access: true }

  [build_hash_lens(head, opts), *tail].reduce { |result_lens, key|
    result_lens.compose_lens(build_hash_lens(key, opts))
  }
end

.struct_lens(*method_names) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/ruby-optics/optics.rb', line 25

def self.struct_lens(*method_names)
  head, *tail = method_names

  [build_struct_lens(head), *tail].reduce { |result_lens, key|
    result_lens.compose_lens(build_struct_lens(key))
  }
end