class RFunc::AbstractOption

Public Class Methods

new(value) click to toggle source

Initializes the class

@param value [Any] the initial value of the Option

@return [AbstractOption] and instance of the class

# File lib/rfunc/option.rb, line 11
def initialize(value)
  @value = value
end

Public Instance Methods

==(object) click to toggle source

Comparator that allows one Option to be compared against another by value

@return [Boolean] true if the Option values are identical and false

if not
# File lib/rfunc/option.rb, line 21
def ==(object)
  object.class == self.class && object.get == @value
end
filter() { |el| ... } click to toggle source

Filters the Some by a given function

@param block [Function] the function which will operate on the

option's value if present (should return Bool) and
be used to determine if a Some of None will be
returned

@return [RFunc::Option] the Option result of the filter

# File lib/rfunc/option.rb, line 38
def filter(&block)
  map {|el| yield(el)}.get_or_else { false } ? self : None.new
end
Also aliased as: find
filter_not() { |el| ... } click to toggle source

Filters the Some by the inverse of a given function

@param block [Function] the function which will operate on the

option's value if present (should return Bool) and
be used to determine if a Some of None will be
returned

@return [RFunc::Option] the Option result of the filter

# File lib/rfunc/option.rb, line 50
def filter_not(&block)
  map {|el| !yield(el) }.get_or_else { false } ? self : None.new
end
find(&block)
Alias for: filter
get() click to toggle source

Extracts the value of the option

@return [Any] the value of the option

# File lib/rfunc/option.rb, line 28
def get; @value end
is_option?(el) click to toggle source

Tests whether or not an object is an Option

@param el [Any] the object to test

@return [Boolean] true if the object is an Option or false if not

# File lib/rfunc/option.rb, line 62
def is_option?(el)
  el.is_a?(AbstractOption)
end

Private Instance Methods

validated_option_type(r) click to toggle source
# File lib/rfunc/option.rb, line 68
def validated_option_type(r)
  raise RFunc::Errors::InvalidReturnType.new(r, AbstractOption) if !is_option?(r)
  r
end