ArcadeEvaluator

This object allows you to evaluate an ArcadeExpression under a given ArcadeProfile. This Object allows you to set up, execute and query information about an Arcade script. For more general information on Arcade and its usages we refer you to the Arcade online documentation.

To construct the ArcadeEvaluator object you need to supply an ArcadeExpression along with an ArcadeProfile. ArcadeExpression is an object that contains the Arcade script plus some additional metadata while ArcadeProfile specifies availability of profile variables and limits what functions are available.

The basic workflow is:

From an ArcadeEvaluator object you can query information to determine

  • Which profile variables are accessed by the script.

  • Which attributes are used by a particular profile variable.

  • If the script is considered stable.

Not all scripts use all the profiles variables. ArcadeEvaluator.profileVariablesUsed returns an array of the names of the profile variables used in the current script. Possible uses include:

  • Informing dependency analysis to determine which scripts need to run when a value of a profile variable changes.

  • Minimizing expensive calculation of unneeded profile variables.

ArcadeEvaluator.getAttributes lets you dig deeper to determine which attributes are required on a specific profile variable. If you are querying a subset of attributes when querying a feature, use this information to ensure the profile variable will have the attributes it requires.

ArcadeEvaluator.isStable property indicates if the given script will return the same value for an identical set of profile variables. For this to be true a script must avoid using unstable builtin functions such as now() or random().

ArcadeEvaluator.isStable can be combined with the knowledge of the used profile variables to construct caches of results. This lets you avoid running scripts when repeated calls with the same profiles variables will not alter the evaluation result.

Since

200.1.0

Constructors

Link copied to clipboard
constructor(expression: ArcadeExpression, profile: ArcadeProfile)

Creates an ArcadeEvaluator object.

Properties

Link copied to clipboard

The Arcade expression of the Arcade evaluator.

Link copied to clipboard

Is a script is considered stable. A script is considered stable if the script will return the same result given the same inputs. There are certain functions listed below that will return different values on each evaluation. Use of these functions means the script is not considered stable.

Link copied to clipboard

The Arcade profile under which the script should evaluate.

Link copied to clipboard

An array of strings containing the names of all profile variables used in the script.

Inherited properties

Link copied to clipboard
open override val loadStatus: StateFlow<LoadStatus>

The load status.

Functions

Link copied to clipboard
suspend fun evaluate(profileVariables: Map<String, Any>): Result<ArcadeEvaluationResult>

Evaluate the script using the supplied profile variables. Each entry of the profileVariables dictionary is placed into the interpreter as a value accessible throughout the script. The name and type of these should comply with the profile the Arcade evaluator has been constructed with. Values are not persisted across evaluations, meaning all required profile variables must be supplied with each evaluation.

Link copied to clipboard
suspend fun getAttributes(variableName: String, attributeNameSource: FeatureTable): Result<List<String>>
suspend fun getAttributes(variableName: String, attributeNameSource: GeoElement): Result<List<String>>

An array of attributes used in the script for a given profile variable. To fully support the wildcard expansion in the expects statement, calculation of used attributes on a profile variable requires an object that can supply a full set of attribute names.

Inherited functions

Link copied to clipboard
open override fun cancelLoad()

Cancels loading metadata for the Loadable object.

Link copied to clipboard
open suspend override fun load(): Result<Unit>

Loads the metadata for the object.

Link copied to clipboard
open suspend override fun retryLoad(): Result<Unit>

Loads or retries loading metadata for the object.