Keeping $Text sorted

(Asaf Keller) #1

Is it possible to sort $Text?

Scenario: I have a Rule that collects tags (a user-defined attribute, $Topics) from notes within a container, and enters these as the $Text of the container:

$MySet = collect(children,$Topics); $Text = $MySet.format("\n")

I would like to keep this $Text sorted alphabetically.

(Mark Anderson) #2


$Text = $MySet.sort.format("\n")

FWIW, collect() returns List-type data (originally is was Set-type) and you can get a de-duped sorted list in one go:

$Text = collect(children,$Topics).unique.sort.format("\n");

I do this a lot. If the ‘rule’ is to persist in my TBX, I generally use $Edict rather than $Rule to lessen the general load. If the source material changes often, I use $Rule but disable the Rule when not needed (…which is sort of how edits came about). Anyway, there are a few options.

More on available Action code operators.

(Asaf Keller) #3

Works like a charm, thanks!
I could not find a relavant solution in aTbRf when I searched for “sort”.
Mark: We, the TB users, cannot say this enough – thank you so much for your excellent and generous (and pro bono!) support!

(Mark Anderson) #4

Thanks for the heads-up on that. I clearly need to resolve that.

(James Fallows) #5

Yes! This is an ongoing act of great value and generosity. Thanks!