Module: Divergent

Defined in:
lib/divergent.rb,
lib/divergent/try.rb,
lib/divergent/try.rb,
lib/divergent/maybe.rb,
lib/divergent/maybe.rb,
lib/divergent/monad.rb,
lib/divergent/errors.rb,
lib/divergent/version.rb

Overview

Divergent is a collection of monad class to do error handling in Ruby.

Currently, it only contains two class:

  1. Try: a container which can wraps possible errors.

  2. Maybe: a container which wraps nil case.

Defined Under Namespace

Modules: Monad, Try Classes: Failure, Maybe, NoSuchElementError, Some, Success, UnSupportedOperationError

Constant Summary collapse

None =

:nodoc: all

Class.new(Maybe) do # :nodoc: all
  include Singleton

  def empty?
    true
  end

  def get
    raise NoSuchElementError, 'no such element in None.get'
  end

  def to_s
    "None"
  end

  alias inspect to_s
end.instance.freeze
VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.Maybe(v) ⇒ Object



235
236
237
# File 'lib/divergent/maybe.rb', line 235

def Maybe(v)
  Maybe.unit(v)
end

.TryObject

Constructs a ‘Try` by calling the passed block. This method will ensure any StandardError is caught and a `Failure` object is returned.



296
297
298
# File 'lib/divergent/try.rb', line 296

def Try
  Try.unit { yield }
end