Home Search

DriveWorks Pro 23
TableMap

Send Feedback

TableMap

Applies a Lambda Function across a provided table of data array.

Returns an array with the result of the Lambda function applied.

Syntax

TableMap(Input Array, Decorator Function, [Include Header Row], [Enable Lazy Evaluation])

Where:

Input Array is the array to iterate over.

Decorator Function is the Lambda Function to apply to the Input Array values.

Include Header Row (optional) is TRUE to include column headers in the evaluation, FALSE (default if excluded) to ignore them.

  • Input Arrays are assumed to include a header row by default. Set this argument to TRUE if the Input Array does not have a header row.

Enable Lazy Evaluation (optional) is TRUE (default if excluded) to evaluate values when accessed, FALSE to evaluate all values when originally called.

Decorator Function

The DWLambda used for the decorator function uses the following syntax:

DWLambda(value, [rowIndex], [columnIndex], Function)

value is the entry from the original array to be evaluated.

  • When TableMap parses the Input Array each cell value is passed to the function.
  • value is a required parameter in the Function argument.

rowIndex (optional) is the row index of the entry being evaluated.

  • When TableMap parses the Input Array, the index of each row is passed to the function.
  • Using rowIndex is optional.

columnIndex (optional) is the column index of the entry being evaluated.

  • When TableMap parses the Input Array, the index of each column is passed to the function.
  • Using columnIndex is optional.

Function is the function to apply to the Input Array values.

Use Rules Insight to insert the required lambda signature into the function.

Lazy Evaluation

Lazy Evaluation is only applied when a Specification is run.

When building a TableMap rule all values in the Input Array are evaluated and can be seen in real time in Table Visualization (in the Drill Down tab of the Rule Builder).

When Enable Lazy Evaluation is TRUE any cell evaluations will be calculated only when that cell is accessed.

For example, the following rule calls a cell in a TableMap function where Enable Lazy Evaluation is TRUE:

TableGetValue(DWVariableTableMap,2,7)

The TableMap function will only evaluate the cell (referenced by Column Index 2 and Row Index 7) in the result.

When Enable Lazy Evaluation is FALSE the evaluation of each cell is conducted immediately when the function is called and then stored.

Lazy Evaluation may require to be disabled due to:

  • Values are required to be pre-loaded so they are not calculated during user interactions.
  • An impure function is being intentionally used (and the external effect is to be applied for all values in the Input Array).

Examples

Example 1

This example removes all inch (") symbols from a table.

Rule

TableMap(
	DwLookupPipeSizeInch,
	DWLambda(value,Substitute(value,"""","")),
	FALSE,
	TRUE
)
  • Input Array is the Table named PipeSizeInch (DWLookupPipeSizeInch).
  • Decorator Function is a DWLambda that uses a Substitute function to replace " ("""") with a blank ("").
  • Include Header Row is False meaning the header row will be ignored from the evaluation. If the header row contains " symbols that are required to be removed use True here.
  • Enable Lazy Evaluation is True to evaluate rules when accessed.

Result

The result is a new array with all cell values that match the decorator function evaluated to remove the " symbol.

Viewed as an array:

{"Outer Diameter","Inner Diameter","Wall Thickness";"0.405","0.269","0.068";"1.25","1.02","0.115";"2.380","1.864","0.258"}

Viewed as a table:

Outer DiameterInner DiameterWall Thickness
0.4050.2690.068
1.251.020.115
2.3801.8640.258

Data (Table named PipeSizeInch)

The original table of data includes inch symbols with each numeric value.

This is treated as a string and would cause any subsequent calculations, that required a number, to return to return a #VALUE! error.

Viewed as a table:

Outer DiameterInner DiameterWall Thickness
0.405"0.269"0.068"
1.25"1.02"0.115"
2.380"1.864"0.258"

Viewed as an array:

When the above table is converted to an array each string value is enclosed with quotes (for example "cell value").

To allow an additional quote to be used within a string, each additional quote is automatically replaced with a double quote.

{"Outer Diameter","Inner Diameter","Wall Thickness";"0.405""","0.269""","0.068""";"1.25""","1.02""","0.115""";"2.380""","1.864""","0.258"""}

Example 2

This example converts all cell values returned by Example 1 above to millimeters.

Rule

TableMap(
	DWVariableRemoveInchSymbol,
	DWVariableConvertInchToMM,
	FALSE,
	FALSE
)
  • Input Array is the array returned from the Variable named RemoveInchSymbol (DWVariableRemoveInchSymbol).

    This is a Variable that uses the TableMap function to remove all inch symbols from an existing table (see Example 1).

  • Decorator Function is the variable ConvertInchToMM which uses a DWLambda to multiply values by 25.4.
  • Include Header Row is False meaning the header row will be ignored from the evaluation. If the header row contains " symbols that are required to be removed use True here.
  • Enable Lazy Evaluation is False to evaluate rules when originally called.

Result

The result is a new array with all cell values that match the decorator function evaluated to be multiplied by 25.4.

Viewed as an array:

{"Outer Diameter","Inner Diameter","Wall Thickness";10.287,6.8326,1.7272;31.75,25.908,2.921;60.452,47.3456,6.5532}

Viewed As Table

Outer DiameterInner DiameterWall Thickness
10.2876.83261.7272
31.7525.9082.921
60.45247.34566.5532

Data (Variable named RemoveInchSymbol)

The data to convert is a Variable returning an array of values that has had the inch symbol removed (see Example 1)

Viewed as a table:

Outer DiameterInner DiameterWall Thickness
0.4050.2690.068
1.251.020.115
2.3801.8640.258

Viewed as an array:

{"Outer Diameter","Inner Diameter","Wall Thickness";"0.405","0.269","0.068";"1.25","1.02","0.115";"2.380","1.864","0.258"}

Example 3

This example will conditionally convert cell values from a specific column into one value, and all other columns to another value.

Rule

TableMap(
	DwLookupPipeSizeInchWithPriceUS,
	DWLambda(Value,
		RowIndex,
		ColumnIndex,
		If(ColumnIndex=4,
			Value*0.81,
			Value*25.4
			)
		),
	FALSE,
	FALSE
	)
  • Input Array is the array returned from the Table named PipeSizeInchWithPriceUS (DwLookupPipeSizeInchWithPriceUS).
  • Decorator Function is a DWLambda that uses an IF function to conditionally multiply values from columnIndex 4 by 0.81 and all other columns by 25.4.
  • Include Header Row is False meaning the header row will be ignored from the evaluation. If the header row contains " symbols that are required to be removed use True here.
  • Enable Lazy Evaluation is False to evaluate rules when originally called.

Result

The result is a new array with values in ColumnIndex 4 multiplied by 0.81 and all other columns multiplied by 25.4.

Viewed as an array:

{"Outer Diameter","Inner Diameter","Wall Thickness","Stock Price";10.287,6.8326,1.7272,23.2632;31.75,25.908,2.921,21.465;60.452,47.3456,6.5532,27.9126}

Viewed As Table

Outer DiameterInner DiameterWall ThicknessStock Price
10.2876.83261.727223.2632
31.7525.9082.92121.465
60.45247.34566.553227.9126

Data (Table named PipeSizeInchWithPriceUS)

The original table of data stored the Stock Price in US dollar (column 4) and sizing information in inches (column 1 to 3)

Viewed As Table

Outer DiameterInner DiameterWall ThicknessStock Price
0.4050.2690.06828.72
1.251.020.11526.5
2.3801.8640.25834.46

Viewed as an array:

{"Outer Diameter","Inner Diameter","Wall Thickness","Stock Price";"0.405","0.269","0.068","28.72";"1.25","1.02","0.115","26.5";"2.380","1.864","0.258","34.46"}

See Also

Higher Order Functions - About higher order functions.

DWLambda - Allows custom, reusable functions to be created.

TableFilterByFunction - Filters an array based on a single column using the provided Lambda Function.

TableFilterByRowFunction - Filters an array using the provided Lambda Function applied to each row.