stencilproject/Stencil

question: how to combine keys of multiple dictionaries in a single list and remove duplicates

claire-lynch-okcupid opened this issue · 0 comments

hello stencil team!
i am working with stencil in the context of a custom swiftgen template.
i am attempting to iterate over a list of dictionaries and extract all the unique keys which will then represent the cases of an enum.
something like this:

{% macro extractUniqueKeys dictionaries %}
public enum AnalyticsPropertyKey: String {
  {% for dict in dictionaries %}
  {% for key,value in dict %}
  // Only want to execute setting key name and declaring case if I haven't already found that key!
  {% set keyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %}
    case {{keyName}} = "{{key}}"
  {% endfor %}
  {% endfor %}
}
{% endmacro %}

Is there a way to do this? I also asked on the swiftgen repo, too, in case that's the better forum. thank you!