Array whose members are a specific type or its empty

I’m trying to create a struct that has an attribute of an array that is either empty or each member is a specific type.

class MyStruct < Dry::Struct
  attribute :my_attribute Types::Arrray.of(Integer) | Types::Array.empty? # this doesn't work but I hope it communicates what I'm trying todo 
end

I’d like the array to be there and if it has anything in it, it must be a certain type, otherwise, it should be empty.

Not sure I understand, what is it that Types::Arrray.of(Integer) lacks here? It should do exactly what you described :slight_smile:

1 Like

Thanks for the reply! I realize after playing with it that just by writing Types::Array.of(Integer) allows the empty array.