Module: Zx::Maybe::Maybeable

Defined in:
lib/zx/maybe.rb

Constant Summary collapse

None =
->(*kwargs) { ::Maybe::None.new(*kwargs) }
Some =
->(*kwargs) { ::Maybe::Some.new(*kwargs) }
Maybe =
->(*kwargs) { ::Maybe.of(*kwargs) }

Instance Method Summary collapse

Instance Method Details

#Maybe(*kwargs) ⇒ Object



10
11
12
# File 'lib/zx/maybe.rb', line 10

def Maybe(*kwargs)
  ::Maybe.of(*kwargs)
end

#None(*kwargs) ⇒ Object



18
19
20
# File 'lib/zx/maybe.rb', line 18

def None(*kwargs)
  ::Maybe::None.new(*kwargs)
end

#Some(*kwargs) ⇒ Object



14
15
16
# File 'lib/zx/maybe.rb', line 14

def Some(*kwargs)
  ::Maybe::Some.new(*kwargs)
end

#Try(default = nil, options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/zx/maybe.rb', line 22

def Try(default = nil, options = {})
  Some yield
rescue StandardError => e
  None[default || options.fetch(:or, nil)]
end