Module: Sheetah::Utils::MonadicResult::Result

Included in:
Failure, Success
Defined in:
lib/sheetah/utils/monadic_result.rb

Constant Summary collapse

UnwrapError =
Class.new(StandardError)
VariantError =
Class.new(UnwrapError)
ValueError =
Class.new(UnwrapError)

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



44
45
46
# File 'lib/sheetah/utils/monadic_result.rb', line 44

def ==(other)
  other.is_a?(self.class) && other.wrapped == wrapped
end

#discardObject



58
59
60
# File 'lib/sheetah/utils/monadic_result.rb', line 58

def discard
  empty? ? self : self.class.new
end

#empty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/sheetah/utils/monadic_result.rb', line 40

def empty?
  wrapped == Unit
end

#initialize(value = Unit) ⇒ Object



36
37
38
# File 'lib/sheetah/utils/monadic_result.rb', line 36

def initialize(value = Unit)
  @wrapped = value
end

#inspectObject Also known as: to_s



48
49
50
51
52
53
54
# File 'lib/sheetah/utils/monadic_result.rb', line 48

def inspect
  if empty?
    "#{variant}()"
  else
    "#{variant}(#{wrapped.inspect})"
  end
end