This version is out of date, covering development from v8.0.0 to v8.x.x. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v8 Icon

List/Set.count


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Property   [other Property type actions]

 List   [operators of similar scope]

 Data manipulation   [other Data manipulation operators]

 Baseline

 


List/set.count

The property .count counts the Number of discrete items in the specified List or Set data type attribute.

This is better used instead of count(list) or List/Set.size.

The subject list is evaluated so can use a literal list or $attribute(note). It can also use more complex expressions to get data as long as the result is an attribute of the List or Set data type.

For example if $KeyAttributes for the current note is "Color;AccentColor;NameFont" then the code

$MyNumber = $KeyAttributes.count; 

is effectively

$MyNumber = ("Color;AccentColor;NameFont").count; 

and not surprisingly returns 3. Note that the count is not all unique values for the attribute across the whole TBX; scope is restricted to 'this' note or another nominated note. Specimen usage:

$MyNumber = $KeyAttributes.count; 

$MyNumber = $KeyAttributes("some other note").count; 

To use .count with a list of items that are attributes or expressions, use list() to pre-create a list:

Works: $MyNumber = list(4+2,9+6).count; (output: 2)

For more complex examples, where list items are action code expressions, it may be necessary to use eval() to wrap each list item expression e.g. list(eval(expressionA),eval(expressionB)).

Examples

The following is a trivial example (given you could use $ChildCount instead) but shows how count can be used in a more subtle way:

$MyNumber = collect(children,$Name).count; 

The result of collect() is a List, in this case a number of note titles. List.count will return the number of values in the list (including duplicates). To get a de-duped count, chain the .unique function before the .count:

$MyNumber = collect(children,$Name).unique.count; 

Similarly, find() returns a List but note that find() does not de-dupe for aliases. Thus test $IsAlias in the query to weed alias results from the returned list:

$MyNumber = find($Prototype=="pProject"&$IsAlias==false&$ChildCount>1).count;