Unpack
Syntax
$set.singleElement()
Description
Unpacks a one-element set by returning the only element as the result. If the input is null
, or the empty set, the result is null
. If the set contains multiple elements, then an error is returned.
See also Pack.
Parameter
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
set | Set | A set or list with only one element to be unpacked. Multi-element sets are not allowed. | yes |
Return value
Type: Number/string/boolean/businss object
The element contained in set
or null
, if the input was null
or the set was empty.
Examples
One-element set
list(1).singleElement()
Output: 1
Empty set
none().singleElement()
Output: null
The empty set created by none()
has no element to unwrap.