All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reference.language.item.html Maven / Gradle / Ivy




    
    Item expressions
    
    

    
    

    
    

    
    
    
    

    


Item expressions

Item expressions are used to retrieve a value from a collection value.
An item expression is a code fragment which produces a value, whose type is determined by the value being retrieved, which can then be used as an input for other operations: print, write, method call and so forth.
An item expression has the form collection[item] where collection is a collection value and item has the type expected by collection.

List item

An item from a List value must be retrieved using an Integer, ranging from 1 to n where n is the number of items in the List value.
If the item value is out of range, an INDEX_OUT_OF_RANGE error will be raised.
The type of the resulting value is the List item type.

Tuple item

An item from a Tuple value must be retrieved using an Integer, ranging from 1 to n where n is the number of items in the Tuple value.
If the item value is out of range, an INDEX_OUT_OF_RANGE error will be raised.
Prompto cannot infer the type of Tuple items, so the type of the resulting value is Any.

Range item

An item from a Range value must be retrieved using an Integer, ranging from 1 to n where n is the number of items in the Range value.
If the item value is out of range, an INDEX_OUT_OF_RANGE error will be raised.
The type of the resulting value is the Range item type.

Dictionary item

An item from a Dictionary value must be retrieved using a Text key.
If the Dictionary has no value for the key, it will return the null value.
The type of the resulting value is the Dictionary item type.

Document item

An item from a Document value must be retrieved using a Text key.
If the Document has no value for the key, it will return the null value.
Prompto cannot infer the type of Document items, so the type of the resulting value is Any.

Text item

Although Text values are considered 'atomic' by Prompto, it can be convenient to sometimes treat them as a List of Character.
An item from a Text value must be retrieved using an Integer, ranging from 1 to n where n is the number of characters in the Text value.
If the item value is out of range, an INDEX_OUT_OF_RANGE error will be raised.
The type of the resulting value is a Character.

Set item

Set items have no given order, so it does not make much sense to retrieve a given Set item.
It is also a slow operation, because Prompto needs to iterate over the items until it reaches the selected one.
It can however be convenient during development to retrieve Set items. This is the only reason why Prompto supports this feature.

An item from a Set value must be retrieved using an Integer, ranging from 1 to n where n is the number of items in the Set value.
If the item value is out range, an INDEX_OUT_OF_RANGE error will be raised.
The type of the resulting value is the Set item type.

You must NOT use Set items in production code. This feature is for development only.

In JavaScript, Set items are retrieved in the order used to create them, which is why in the above example, the retrieved values are the same as the input values. You must NOT rely on this behavior, which is a side effect of the JavaScript engine implementation.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy