Sha256: 7e37f7a878aca0b22bdd0ca2bfedde1f5a96423ec9a3f09769ed4490136a44bc

Contents?: true

Size: 977 Bytes

Versions: 3

Compression:

Stored size: 977 Bytes

Contents

require 'dry/monads/either'
require 'dry/monads/maybe'
require 'dry/monads/try'

module Dry
  # @api public
  module Monads
    extend self

    # Stores the given value in one of the subtypes of {Maybe} monad.
    # It is essentially a wrapper for {Maybe.lift}.
    #
    # @param value [Object] the value to be stored in the monad
    # @return [Maybe::Some, Maybe::None]
    def Maybe(value)
      Maybe.lift(value)
    end

    # @param value [Object] the value to be stored in the monad
    # @return [Maybe::Some]
    def Some(value)
      Maybe::Some.new(value)
    end

    # @return [Maybe::None]
    def None
      Maybe::Some::None.instance
    end

    # @param value [Object] the value to be stored in the monad
    # @return [Either::Right]
    def Right(value)
      Either::Right.new(value)
    end

    # @param value [Object] the value to be stored in the monad
    # @return [Either::Left]
    def Left(value)
      Either::Left.new(value)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-monads-0.2.1 lib/dry/monads.rb
dry-monads-0.2.0 lib/dry/monads.rb
dry-monads-0.1.1 lib/dry/monads.rb