lib/dry/monads/validated.rb in dry-monads-1.3.4 vs lib/dry/monads/validated.rb in dry-monads-1.3.5

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'dry/monads/conversion_stubs' require 'dry/monads/constants' require 'dry/monads/right_biased' module Dry @@ -47,11 +49,11 @@ # Bind/flat_map is not implemented # def bind(*) # See https://typelevel.org/cats/datatypes/validated.html for details on why - raise NotImplementedError, "Validated is not a monad because it would violate the monad laws" + raise NotImplementedError, 'Validated is not a monad because it would violate the monad laws' end # Valid result # class Valid < Validated @@ -119,11 +121,11 @@ end # @return [String] def inspect if Unit.equal?(@value) - "Valid()" + 'Valid()' else "Valid(#{@value.inspect})" end end alias_method :to_s, :inspect @@ -165,14 +167,14 @@ # @overload apply # @yieldreturn [Validated::Valid,Validated::Invalid] # @return [Validated::Invalid] # def apply(val = Undefined) - Undefined. - default(val) { yield }. - alt_map { |v| @error + v }. - fmap { return self } + Undefined + .default(val) { yield } + .alt_map { |v| @error + v } + .fmap { return self } end # Lifts a block/proc over Invalid # # @overload alt_map(proc) @@ -209,11 +211,11 @@ Undefined.default(proc, block).call end # @return [String] def inspect - "Invalid(#{ @error.inspect })" + "Invalid(#{@error.inspect})" end alias_method :to_s, :inspect # @param other [Object] # @return [Boolean] @@ -223,11 +225,10 @@ end # Mixin with Validated constructors # module Mixin - # Successful validation result # @see Dry::Monads::Validated::Valid Valid = Valid # Unsuccessful validation result @@ -248,10 +249,11 @@ # @return [Valdated::Valid] # def Valid(value = Undefined, &block) v = Undefined.default(value, block) raise ArgumentError, 'No value given' if !value.nil? && v.nil? + Valid.new(v) end # Invalid constructor # @@ -264,9 +266,10 @@ # @return [Valdated::Invalid] # def Invalid(value = Undefined, &block) v = Undefined.default(value, block) raise ArgumentError, 'No value given' if !value.nil? && v.nil? + Invalid.new(v, RightBiased::Left.trace_caller) end end include Constructors