Skip to content

Count

Name Mandatory Description Default Type
⬅️ Input The input of this shard is ignored. Any
Output ➡️ Outputs the count of characters, elements, or key-value pairs in the specified variable. If the variable type does not match, it outputs 0. Int
Name No The name of the variable. `` StringVar(Any)
Key No The key of the value to read from the table (parameter applicable only if the target variable is a table). none Any
Global No If the variable is available to all of the wires in the same mesh. false Bool

This shard counts the sequence, string or table variable specified in the Name parameter. If the variable specified is a string, it will count the number of characters. If the variable specified is a sequence, it will count the number of elements. If the variable specified is a table, it will count the number of key-value pairs.If the variable is left empty and instead an input is provided, the input will be counted instead.

Details

Count parses the value passed to it in the :Name parameter, and returns the count of characters, elements, or key-value pairs depending on whether the data type passed to it was a string, a sequence, or a table.

If this shard is applied to a number it returns zero as the count.

This shard works on both sequences and tables. Parameter :Key applies only to tables.

Since variables may be locally scoped (created with (:Global false); exists only for current wire) or globally scoped (created with (:Global true); exists for all wires of that mesh), both parameters :Global and :Name are used in combination to identify the correct variable to count.

Input field is ignored and the output of this shard is the count value in Int type.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
; counting in locally scoped variables
"Shards" >= string
Count(Name: string) | Log     ; no. of characters => 6 

[10 20 30] >= sequence
Count(sequence) | Log         ; no. of elements => 3        

{k1: 11 k2: 22} >= table
Count(table) | Log           ; no. of key-value pairs => 2

12345 >= number
Count(number) | Log          ; zero count for numbers => 0

; counting in same-name local and global variables
"Local Shards" >= stringvar    ; create a local variable   
"Global Shards" | Set(stringvar Global: true)  ; create global variable   

Count(stringvar) | Log        ; characters in local var => 12
Count(stringvar Global: true) | Log  ; characters in global var => 13

[info] Set - Warning: setting an already exposed variable "stringvar", use Update to avoid this warning.
[info] [sample-wire] 6
[info] [sample-wire] 3
[info] [sample-wire] 2
[info] [sample-wire] 0
[info] [sample-wire] 12
[info] [sample-wire] 13