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

count(list)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 List   [operators of similar scope]

 Mathematical   [other Mathematical operators]

 Baseline

 


count(list)

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

It is usually easier to use List/Set.count or alternatively List/Set.size.

count(attribute)

The attribute argument is evaluated so can use, $attribute(note) or more complex expressions to get data - as long as the result is an attribute of the Set data type.

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

count($KeyAttributes) 

is effectively

count("Color;Color2;NameFont") 

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():

Works: $MyNum = count(list(4+2,9+6)) (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 we could use $ChildCount instead) but shows how count can be used in a more subtle way:

$MyNum = count(collect(children,$Name)) 

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

count(collect(children,$Name).unique) 



A Tinderbox Reference File : Actions & Rules : Operators : Full Operator List : count(list)