The [tie->foreach] method invokes a capture block on each element in the tie. The method requires a capture block to be passed to it. The capture block is invoked on each element of the tie in turn (i.e. the capture block is invoked with each element of the tie). The current value in the tie can be accessed using the #1 variable.
#myTie->forEach => {
}
This example calculates the sum of each item in the tie. The sum is output.
Code
local( total = 0 );
local( myTie = tie( array( 1, 2, 3, 4, 5 ), list( 6, 7, 8, 9, 10 ) );
#myTie->forEach => {
#total += #1; // Add to sum
} // Close forEach
#total;
Result
55
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Recent Comments