Sha256: 3ae2eee9c614b607de63c6a96d259136be65b69a8e20d2bfab7bc9c6af262aa1

Contents?: true

Size: 712 Bytes

Versions: 3

Compression:

Stored size: 712 Bytes

Contents

require 'dry/equalizer'

module Dry
  module Types
    class Result
      include Dry::Equalizer(:input)

      attr_reader :input

      def initialize(input)
        @input = input
      end

      class Success < Result
        def success?
          true
        end

        def failure?
          false
        end
      end

      class Failure < Result
        include Dry::Equalizer(:input, :error)

        attr_reader :error

        def initialize(input, error)
          super(input)
          @error = error
        end

        def to_s
          error.to_s
        end

        def success?
          false
        end

        def failure?
          true
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-types-0.9.2 lib/dry/types/result.rb
dry-types-0.9.1 lib/dry/types/result.rb
dry-types-0.9.0 lib/dry/types/result.rb