What might be the simplest way to express this type if it is possible? Would monads work here? Is there a better way?
class VersionedMetadata < Dry::Struct attribute :version, Types::Strict::Integer # how do I express this? attribute :metadata, MetadataV1 # if version == 1 attribute :metadata, MetadataV2 # if version == 2 attribute :metadata, UnsupportedVersionMetadata # any other value of version end
Yes I am aware that the ‘type’ attribute can allow for polymorphic construction but that isn’t quite the same as what I’m hoping to learn how to do. Would love to be able to change the type of attribute B based on arbitrary values of attribute A.