Do you really need a list? What type does selectedReplicas return? There might be a better pattern matching that won't require you to create a list.