Sha256: 932d7ec376ae12d2b702935d0fde6d7486658862d642650f61775a46a69d3764

Contents?: true

Size: 587 Bytes

Versions: 4

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

4 entries across 4 versions & 1 rubygems

Version Path
dry-types-1.6.1 lib/dry/types/extensions/monads.rb
dry-types-1.6.0 lib/dry/types/extensions/monads.rb
dry-types-1.5.1 lib/dry/types/extensions/monads.rb
dry-types-1.5.0 lib/dry/types/extensions/monads.rb