Class: Option

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/totally_lazy/option.rb

Direct Known Subclasses

None, Some

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.noneObject



41
42
43
# File 'lib/totally_lazy/option.rb', line 41

def self.none
  NONE
end

.option(value) ⇒ Object



33
34
35
# File 'lib/totally_lazy/option.rb', line 33

def self.option(value)
  value.nil? ? none : some(value)
end

.some(value) ⇒ Object



37
38
39
# File 'lib/totally_lazy/option.rb', line 37

def self.some(value)
  Some.new(value)
end

Instance Method Details

#flattenObject



54
55
56
# File 'lib/totally_lazy/option.rb', line 54

def flatten
  flat_map(identity)
end

#is?(fn_pred = nil, &block_pred) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/totally_lazy/option.rb', line 49

def is?(fn_pred=nil, &block_pred)
  assert_funcs(fn_pred, block_given?)
  exists?(block_given? ? ->(value) { block_pred.call(value) } : fn_pred)
end

#is_defined?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/totally_lazy/option.rb', line 45

def is_defined?
  !is_empty?
end