3 ms·
Yes that makes sense, thanks. Also, my comment was about the amount of boilerplate required, but that can be vastly reduced by writing `process_template` in a
by pansa2 1y ago
Yes that makes sense, thanks.
Also, my comment was about the amount of boilerplate required, but that can be vastly reduced by writing `process_template` in a more functional style instead of the highly-imperative (Golang-like?) style used in the article. The first `process_template` example is just:
def process_template(template: Template) -> str:
return ''.join(interleave_longest(template.strings, map(process_value, template.values)))
And the second is something like:
def process_template(template: Template) -> tuple[str, tuple]:
return (
''.join(interleave_longest(template.strings, ['?'] * len(template.values))),
map(process_value, template.values)
)