[when-with-enum] Refactoring: removed code duplication when iterating over constants