class RFunc::Some

Public Class Methods

new(something) click to toggle source
Calls superclass method RFunc::AbstractOption::new
# File lib/rfunc/option.rb, line 75
def initialize(something)
  throw "RFunc::Some cannot be initialized with a nil" if something.nil?
  super(something)
end

Public Instance Methods

collect() { |value| ... } click to toggle source

Operates on the value of the Option if it exists and meets a criteria

@param block [Function] the block that can be used to modify the value

(should be a case statement with nil return for non operation)

@return [Option] the resulting Option containing a value modified by

the supplied block
# File lib/rfunc/option.rb, line 165
def collect(&block)
  result = yield(@value)
  result.nil? ? None.new : Some.new(result)
end
count() { |value| ... } click to toggle source

Counts the number of elements for which the block returns true

@param block [Function] the function that determines whether the

value should be counted

@return [Int] 1 if the block returned true for this Option value or 0 if not

# File lib/rfunc/option.rb, line 177
def count(&block)
  yield(value) == true ? 1 : 0
end
empty?() click to toggle source

Indicates if the Option has a value

@return [Boolean] false

# File lib/rfunc/option.rb, line 118
def empty?
  false
end
flat_map() { |get| ... } click to toggle source

Applies a function to the value of the Option and flattens the resulting Option into a single Option

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

Option's value (should return an Option)

@return [RFunc::Option] the Option result of flattening the current

provided function's option
# File lib/rfunc/option.rb, line 131
def flat_map(&block)
  validated_option_type(yield(get))
end
flatten() click to toggle source

Flattens nested Options into a single option

@return [Option] a Some if the contained value is a Some or a None

if not
# File lib/rfunc/option.rb, line 153
def flatten
  is_option?(@value) ? @value : self
end
fold(alternate) { |get| ... } click to toggle source

Operates on the value of the Option

@param alternate [Any] the value to return if the Option is a None @param block [Function] the function which will operate on the

current Option's value

@return [Any] the result of applying the supplied block to the current

Option value
# File lib/rfunc/option.rb, line 144
def fold(alternate, &block)
  yield(get)
end
for_all() { |value| ... } click to toggle source

Determines if the current Option value satisfies the supplied block

@param block [Function] the function that determines whether the

value satisfies an expectation

@return [Boolean] true if the block returns true for the value or false if not

# File lib/rfunc/option.rb, line 188
def for_all(&block)
  yield(@value)
end
for_each() { |value| ... } click to toggle source

Executes the provided block with the current Option value

@param block [Function] the function that takes the current Option's value

@return [Nil] nil

# File lib/rfunc/option.rb, line 198
def for_each(&block)
  yield(@value)
  nil
end
get_or_else(&block) click to toggle source

Maintains signiture parity with None.get_or_else

@param block [Function] the value that would return if the current

Option was a None

@return [Any] Option value

# File lib/rfunc/option.rb, line 87
def get_or_else(&block)
  get
end
map() { |value| ... } click to toggle source

Operates on the Option value

@param block [Function] the function which will be used to operate

on the Option's value

@return [Option] the result of the function's operation

as an Option
# File lib/rfunc/option.rb, line 110
def map(&block)
  Option.new(yield(@value))
end
or_else(v) click to toggle source

Maintains signiture parity with None.or_else

@param v [Option] the option that would return if the present Option

were a None

@return [Option] the current option

# File lib/rfunc/option.rb, line 98
def or_else(v)
  self
end