Operator Type:
Operator Scope of Action:
Operator Purpose:
Operator First Added:
Operator Altered:
Function [other Function type actions]
List [operators of similar scope]
Stream parsing [other Stream parsing operators]
9.1.0
Stream.eachLine(LoopVar[:condition]){ action(s) }
The .eachLine() operator, iterates through each line of a steam, where a line is one or more characters ending in a carriage return, line feed, unicode paragraph separator, or the end of the string (so in $Text, it means discrete paragraphs).
Each line, in turn, is bound to a temporary variable LoopVar, and the action is then performed. The name of the variable is set by the user when writing the code, i.e. it is whatever string is entered where LoopVar is shown above. Something like 'aLine' might be a more useful variable name.
If the optional condition is specified, only lines that satisfy the condition are passed to the action.
For example:
$MyNumber=0;
$Text.eachLine(aLine){
$MyNumber=$MyNumber+1;
};
will set $MyNumber to the number of lines (paragraphs!) in the $Text of this note.
$MyNumber=0;
$Text.eachLine(aLine:aLine.contains("@")){
$MyNumber=$MyNumber+1;
};
will set $MyNumber to the number of lines in the $Text that contain the "@" symbol.
When parsing text paragraphs, this operator can substitute for the older method of chaining .paragraphList.each(){}.