Module: Fear::Option::Mixin

Included in:
Mixin
Defined in:
lib/fear/option.rb

Overview

Include this mixin to access convenient factory methods.

Examples:

include Fear::Option::Mixin

Option(17)  #=> #<Fear::Some value=17>
Option(nil) #=> #<Fear::None>
Some(17)    #=> #<Fear::Some value=17>
None()      #=> #<Fear::None>

Instance Method Summary collapse

Instance Method Details

#NoneNone

Returns:



185
186
187
# File 'lib/fear/option.rb', line 185

def None
  None.new
end

#Option(value) ⇒ Some, None

An Option factory which creates Some if the argument is not nil, and None if it is nil.

Parameters:

  • value (any)

Returns:



176
177
178
179
180
181
182
# File 'lib/fear/option.rb', line 176

def Option(value)
  if value.nil?
    None()
  else
    Some(value)
  end
end

#Some(value) ⇒ None

Parameters:

  • value (any)

    except nil

Returns:



191
192
193
# File 'lib/fear/option.rb', line 191

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