EDIT: As correctly pointed by @alassek this is related to a known issue with #try
and Default
I was expecting to be able to use to_monad
on a type with default values.
Is this an expected behavior or am I missing something?
Success
seems to be wrapped correctly but not Failure
.
require "dry/types"
Dry::Types.load_extensions(:monads)
Types = Dry.Types()
One = Types::Symbol.enum(*%i(a b c))
Two = Types::Symbol.default(:c).enum(*%i(c d e))
One.try(:w).to_monad
# => Failure([#<Dry::Types::ConstraintError: :w violates constraints (included_in?([:c, :d, :e], :w) failed)>, :w])
Two.try(:d).to_monad
# => Success(:d)
Two.try(:w).to_monad
# Dry::Types::ConstraintError: :w violates constraints (included_in?([:c, :d, :e], :w) failed)