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:



177
178
179
# File 'lib/fear/option.rb', line 177

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:



168
169
170
171
172
173
174
# File 'lib/fear/option.rb', line 168

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

#Some(value) ⇒ None

Parameters:

  • value (any)

    except nil

Returns:



183
184
185
# File 'lib/fear/option.rb', line 183

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