Sha256: bc64547d81db063f295d7895296d450c53c39c82c300c656a27802f025be8ff2

Contents?: true

Size: 587 Bytes

Versions: 7

Compression:

Stored size: 587 Bytes

Contents

# frozen_string_literal: true

require 'dry/monads/result'

module Dry
  module Types
    # Monad extension for Result
    #
    # @api public
    class Result
      include Dry::Monads::Result::Mixin

      # Turn result into a monad
      #
      # This makes result objects work with dry-monads (or anything with a compatible interface)
      #
      # @return [Dry::Monads::Success,Dry::Monads::Failure]
      #
      # @api public
      def to_monad
        if success?
          Success(input)
        else
          Failure([error, input])
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/dry-types-1.4.0/lib/dry/types/extensions/monads.rb
dry-types-1.4.0 lib/dry/types/extensions/monads.rb
dry-types-1.3.1 lib/dry/types/extensions/monads.rb
dry-types-1.3.0 lib/dry/types/extensions/monads.rb
dry-types-1.2.2 lib/dry/types/extensions/monads.rb
dry-types-1.2.1 lib/dry/types/extensions/monads.rb
dry-types-1.2.0 lib/dry/types/extensions/monads.rb