Class: Option::Some

Inherits:
Object
  • Object
show all
Defined in:
lib/trither/option.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



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

def initialize(value)
  @value = value
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  false
end

#fetch(_default) ⇒ Object



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

def fetch(_default)
  @value
end

#flat_mapObject



49
50
51
52
53
54
55
56
# File 'lib/trither/option.rb', line 49

def flat_map
  result = yield @value
  if result.nil?
    None
  else
    result
  end
end

#get_or_elseObject



58
59
60
# File 'lib/trither/option.rb', line 58

def get_or_else
  @value
end

#mapObject



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

def map
  Option.make(yield @value)
end