Sha256: 6568aa61a61d2ea752bae7a178c7e214a195f05f5ac0e84778214c478dd66ff7

Contents?: true

Size: 1003 Bytes

Versions: 2

Compression:

Stored size: 1003 Bytes

Contents

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

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

2 entries across 2 versions & 1 rubygems

Version Path
dry-monads-0.3.1 lib/dry/monads.rb
dry-monads-0.3.0 lib/dry/monads.rb