Page 1 of 1

[SNIPPET] Format List of Values

Posted: 09 Feb 2023, 12:08
by rednoah
The List.joining() and List.joiningDistinct() methods can be used to convert a List object into a String object.


e.g. join season years with dash enclosed in parentheses:

Format: Select all

{ sy.joining('-', '(', ')') }

Code: Select all

(2002-2003)

e.g. join unique audio language properties:

Format: Select all

{ audio.language.joiningDistinct(', ', '[', ']') }

Code: Select all

[ca, en, es, fr, it, nl]



Implementation Notes:

:idea: Empty elements are ignored:

Format: Select all

{ ['1', null, '', '2'].joining('-', '[', ']') }

Code: Select all

[1-2]

:idea: Empty lists do not yield empty brackets [] and instead unwind the expression:

Format: Select all

{ [].joining('-', '[', ']') }

Error: Select all

Collection did not yield any values: []