View Single Post
Old 01-10-2023, 09:22 PM   #474
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,085
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Would there be any general use for a first_in_list(val, separator, value [, value]*) type function?

It would check a list for each pattern in order, and then return the found list item as the value.

Template: first_in_list($tags, ',', "Fanfiction.Crossover")
List contents: Fanfiction.Crossover, Fanfiction.Half-Life & Portal, Fanfiction.Mass Effect
Template value: Fanfiction.Crossover

Template: first_in_list(list, ',', "Explicit", "Mature Audiences", "Teen and Up Audiences", "General Audiences", "Not Rated")
List contents: General Audiences, Explicit, Not Rated, Not Rated
Template value: Explicit

Regex pattern matching may be useful but as with the in/inlist, it lead to unintended results:

Template: first_in_list(list, ',', "foo", "^foobar")
List contents: foobar, foo, bar, bar, foo
Template value: foobar
whoops! the regex matched 'foo'

EDIT: Perhaps as a custom function.

Last edited by ownedbycats; 01-11-2023 at 07:50 AM.
ownedbycats is offline   Reply With Quote