Class: None

Inherits:
Option show all
Includes:
LambdaBlock
Defined in:
lib/totally_lazy/option.rb

Instance Method Summary collapse

Methods inherited from Option

#flatten, #is?, #is_defined?, none, option, some

Instance Method Details

#<=>(other) ⇒ Object



214
215
216
# File 'lib/totally_lazy/option.rb', line 214

def <=>(other)
  other == NONE
end

#contains?(value) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/totally_lazy/option.rb', line 150

def contains?(value)
  false
end

#enumeratorObject



204
205
206
207
208
# File 'lib/totally_lazy/option.rb', line 204

def enumerator
  Enumerator.new { |y|
    raise StopIteration.new
  }
end

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

Returns:

  • (Boolean)


154
155
156
157
# File 'lib/totally_lazy/option.rb', line 154

def exists?(fn_pred=nil, &block_pred)
  assert_funcs(fn_pred, block_given?)
  false
end

#flat_map(fn = nil, &block) ⇒ Object

function should return an option



164
165
166
167
# File 'lib/totally_lazy/option.rb', line 164

def flat_map(fn=nil, &block) # function should return an option
  assert_funcs(fn, block_given?)
  none
end

#fold(seed, fn = nil &block) ⇒ Object Also known as: fold_left



169
170
171
172
# File 'lib/totally_lazy/option.rb', line 169

def fold(seed, fn=nil &block)
  assert_funcs(fn, block_given?)
  seed
end

#getObject



180
181
182
# File 'lib/totally_lazy/option.rb', line 180

def get
  raise NoSuchElementException.new
end

#get_or_else(value_or_fn = nil, &block) ⇒ Object Also known as: or_else



184
185
186
187
188
189
190
191
# File 'lib/totally_lazy/option.rb', line 184

def get_or_else(value_or_fn=nil, &block)
  assert_funcs(value_or_fn, block_given?)
  if (value_or_fn.respond_to? :call) || block_given?
    block_given? ? block.call : value_or_fn.()
  else
    value_or_fn
  end
end

#get_or_nilObject



195
196
197
# File 'lib/totally_lazy/option.rb', line 195

def get_or_nil
  nil
end

#get_or_raise(error) ⇒ Object Also known as: get_or_throw



199
200
201
# File 'lib/totally_lazy/option.rb', line 199

def get_or_raise(error)
  raise error
end

#is_empty?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/totally_lazy/option.rb', line 146

def is_empty?
  true
end

#map(fn = nil, &block) ⇒ Object



159
160
161
162
# File 'lib/totally_lazy/option.rb', line 159

def map(fn=nil, &block)
  assert_funcs(fn, block_given?)
  none
end

#sizeObject



176
177
178
# File 'lib/totally_lazy/option.rb', line 176

def size
  0
end

#to_either(value) ⇒ Object



210
211
212
# File 'lib/totally_lazy/option.rb', line 210

def to_either(value)
  left(value)
end

#to_sObject



218
219
220
# File 'lib/totally_lazy/option.rb', line 218

def to_s
  'none'
end