Sha256: 828673b2fd94ecd404972a7fea32a72eb076a41ab0c45e383a25f7f98a4cbcf2

Contents?: true

Size: 611 Bytes

Versions: 1

Compression:

Stored size: 611 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

1 entries across 1 versions & 1 rubygems

Version Path
dry-schema-1.14.0 lib/dry/schema/extensions/monads.rb