class Monadify::Some

Attributes

value[R]

Public Class Methods

new(val) click to toggle source
# File lib/monadify/option/some.rb, line 6
def initialize(val)
  @value = val
end

Public Instance Methods

empty?() click to toggle source
# File lib/monadify/option/some.rb, line 10
def empty?
  false
end
flatmap() { |value| ... } click to toggle source
# File lib/monadify/option/some.rb, line 29
def flatmap
  begin
    return_option = yield value
    case return_option
    when Monadify::None
      return_option
    when Monadify::Some
      Monadify::Some.new(return_option.value)
    else
      raise NotAnOptionError
    end
  rescue NotAnOptionError
    raise ArgumentError, 'The block should return an Option'
  rescue ArgumentError, NameError, TypeError
    raise
  rescue
    Monadify::None.new
  end
end
map() { |value| ... } click to toggle source
# File lib/monadify/option/some.rb, line 14
def map
  begin
    return_val = yield value
    if return_val.nil?
      Monadify::None.new
    else
      Monadify::Some.new(return_val)
    end
  rescue ArgumentError, NameError, TypeError
    raise
  rescue
    Monadify::None.new
  end
end