Page 1 of 1

Using {"$genres"} returns empty brackets if null

Posted: 27 Mar 2017, 06:34
by cheaters
I am positive someone has the solution for this. I couldn't come up with it after doing a few hour of playing around with it.

My movie format looks like this:

Code: Select all

{"$ny"} {"[$certification]"} {"[$runtime min]"} {"$genres"} {"[$imdbid, $rating]"}
Problem is that when using genres instead of genre, brackets are included. However, If genres returns a null value I get nothing but a pair of [] in my title. I tried using:

Code: Select all

{"$ny"} {"[$certification]"} {"[$runtime min]"} {replaceAll([], replacement = "")"$genres"} {"[$imdbid, $rating]"}
That failed because it removed the brackets and genres.

I tried to change the sample movie from Avatar to a movie that would return empty brackets to test formulas, couldn't figure that out, too convoluted.

Any help?

Re: Using {"$genres"} returns empty brackets if null

Posted: 27 Mar 2017, 06:58
by rednoah
genres is never null. If it's empty then you'll get an empty List.

e.g. check if genres is non-empty:

Code: Select all

{genres ?: null}

I'd just use genre though, which will fail, and thus give you the behaviour you want:

Code: Select all

{ny} {[certification]} {[runtime + ' min']} {[genre]} {[imdbid, rating]}

Re: Using {"$genres"} returns empty brackets if null

Posted: 27 Mar 2017, 07:28
by cheaters
I am trying to get the entire list and if it's empty (no genres) then no empty brackets.

Re: Using {"$genres"} returns empty brackets if null

Posted: 27 Mar 2017, 07:52
by rednoah
Here's the solution:

Code: Select all

{ny} {[certification]} {[runtime + ' min']} {genres.take(3) ?: null} {[imdbid, rating]}
It'll limit the number of genres to 3 because there are some movies that supposedly belong to an insane number of genres.


EDIT:

The unwind-on-undefined behaviour has been extended to include null / Empty String and (new) Empty List with r4960.

Re: Using {"$genres"} returns empty brackets if null

Posted: 02 Apr 2017, 08:57
by cheaters
Thanks a lot, this works fine.