Sha256: 4c3cbb0cbd87a43cbba83904d31d4d86748f4f5341f5d3248a9829418a6e2e63

Contents?: true

Size: 473 Bytes

Versions: 1

Compression:

Stored size: 473 Bytes

Contents

require 'kleisli/maybe'
require 'dry/types/decorator'

module Dry
  module Types
    class Maybe
      include Decorator
      include Builder

      def call(input)
        input.is_a?(Kleisli::Maybe) ? input : Maybe(type[input])
      end
      alias_method :[], :call

      def default(value)
        if value.nil?
          raise ArgumentError, "nil cannot be used as a default of an optional type"
        else
          super
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-types-0.7.0 lib/dry/types/maybe.rb