[SNIPPET] Format List of Values

All about user-defined episode / movie format expressions
Post Reply
User avatar
rednoah
The Source
Posts: 21687
Joined: 16 Nov 2011, 08:59

[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:

Code: Select all

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

Code: Select all

(2002-2003)

e.g. join unique audio language properties:

Code: Select all

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

Code: Select all

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



Implementation Notes:

:idea: Empty elements are ignored:

Code: Select all

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

Code: Select all

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

Code: Select all

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

Code: Select all

// Collection did not yield any values: []
:idea: Please read the FAQ and How to Request Help.
Post Reply