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

Jump to the current version of aTbRef

TinderboxSix 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]

 6.4.0

 


List/set.count

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

Alternatively, use 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;Color2;NameFont" then the code

$KeyAttributes.count 

is effectively

("Color;Color2;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:

count($KeyAttributes) 

count($KeyAttributes(some other note)) 

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

Works: $MyNum = 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:

$MyNum = 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:

collect(children,$Name).unique.count 



A Tinderbox Reference File : Actions & Rules : Operators : Full Operator List : List/Set.count