[SNIPPET] Format List of Values

All about user-defined episode / movie / file name format expressions
Post Reply
User avatar
rednoah
The Source
Posts: 23469
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

[SNIPPET] Format List of Values

Post 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: []
:idea: Please read the FAQ and How to Request Help.
Post Reply