Sha256: 12c0290a083ad55a59d386933a6613c853755e686e9ddbf94ae44e3404ec3d11

Contents?: true

Size: 609 Bytes

Versions: 7

Compression:

Stored size: 609 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"

# preload monads
Dry::Monads[:result]

module Dry
  module Schema
    # 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(self)
        else
          Failure(self)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-schema-1.13.3 lib/dry/schema/extensions/monads.rb
dry-schema-1.13.2 lib/dry/schema/extensions/monads.rb
dry-schema-1.13.1 lib/dry/schema/extensions/monads.rb
dry-schema-1.13.0 lib/dry/schema/extensions/monads.rb
dry-schema-1.12.0 lib/dry/schema/extensions/monads.rb
dry-schema-1.11.3 lib/dry/schema/extensions/monads.rb
dry-schema-1.11.2 lib/dry/schema/extensions/monads.rb