Well, I was about to reply back that this is not a valid use case, but it got me curious and I think it may have let me to a bug in the tuple string item evaluator.
Items in a list are not ordered by definition and you should not rely on any kind of ordering like “remove the last one”. But I’ve had cases where I need to get only the first out of possibly multiple results (like finding a MAC address on a host).
While sets are not ordered in principle, in practice I find they generally are; and operations like “unique values of” that create a Set, generally create an Ordered Set. We can concatenate the results together with the comma-space characters ", ", and then evaluate them as Tuple String Items. Then we can use the “integers in ()” inspector to just get a particular few of those tuple string items. This first let me to this:
q: number of tuple string items of ("one, two, three")
A: 3
T: 0.081 ms
I: singular integer
q: tuple string items (1;2) of ("one, two, three")
A: two
A: three
T: 0.042 ms
I: plural string
q: tuple string items (integers in (0, number of tuple string items of it - 2)) of ("one, two, three")
A: one
A: two
T: 0.095 ms
I: plural string
What about edge cases? Need to test if there are fewer than three results, or only one result, so …
q: tuple string items (integers in (0, number of tuple string items of it - 2)) of ("one")
A: one
A: one
T: 0.100 ms
I: plural string
Whoa, that’s not what I was expecting (I was actually expecting an error). Based on this, when I retrieve tuple string item -1, I get the first item again. At first I thought that negative indexes might walk back from the last item, but no, it seems that passing any negative index returns the first item:
q: tuple string items (-2) of ("one, two, three")
A: one
T: 0.046 ms
I: plural string
So, it takes a little case logic…but again, I’m reaching here, what is it that you really want? If there’s one result, print it? If there’s more than one, present one less than the total number of results? If there were five results, you want to show the first four of them?
q: tuple string items (integers in (0, (if number of tuple string items of it > 2 then number of tuple string items of it - 2 else 0))) of ("one")
A: one
T: 0.089 ms
I: plural string
q: tuple string items (integers in (0, (if number of tuple string items of it > 2 then number of tuple string items of it - 2 else 0))) of ("one, two")
A: one
T: 0.095 ms
I: plural string
q: tuple string items (integers in (0, (if number of tuple string items of it > 2 then number of tuple string items of it - 2 else 0))) of ("one, two, three")
A: one
A: two
T: 0.135 ms
I: plural string