Class: Option::Some

Inherits:
Trither::Box show all
Includes:
Trither::BasicTypes
Defined in:
lib/trither/option.rb,
lib/trither/option.rb

Constant Summary

Constants included from Trither::BasicTypes

Trither::BasicTypes::C, Trither::BasicTypes::Func0, Trither::BasicTypes::Func1, Trither::BasicTypes::Predicate

Constants inherited from Trither::Box

Trither::Box::C

Instance Method Summary collapse

Methods inherited from Trither::Box

#==, #initialize

Constructor Details

This class inherits a constructor from Trither::Box

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/trither/option.rb', line 90

def empty?
  false
end

#fetch(_default) ⇒ Object



100
101
102
# File 'lib/trither/option.rb', line 100

def fetch(_default)
  @value
end

#filterObject



95
96
97
# File 'lib/trither/option.rb', line 95

def filter
  yield(@value) ? self : None
end

#flat_mapObject



110
111
112
113
114
115
116
117
# File 'lib/trither/option.rb', line 110

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

#get_or_elseObject



125
126
127
# File 'lib/trither/option.rb', line 125

def get_or_else
  @value
end

#mapObject



105
106
107
# File 'lib/trither/option.rb', line 105

def map
  Option.make(yield @value)
end

#or_elseObject



120
121
122
# File 'lib/trither/option.rb', line 120

def or_else
  self
end