Retrieves the item at a specific index in the list. Args: index (int): The index to retrieve. Returns: Any: The value of the element at the specified index. Raises: :class:`~couchbase.exceptions.InvalidArgumentException`: If the index is
(self, index: int)
| 209 | raise InvalidArgumentException(message=f'Index: {index} is out of range.') from None |
| 210 | |
| 211 | def get_at(self, index: int) -> Any: |
| 212 | """Retrieves the item at a specific index in the list. |
| 213 | |
| 214 | Args: |
| 215 | index (int): The index to retrieve. |
| 216 | |
| 217 | Returns: |
| 218 | Any: The value of the element at the specified index. |
| 219 | |
| 220 | Raises: |
| 221 | :class:`~couchbase.exceptions.InvalidArgumentException`: If the index is out of range. |
| 222 | |
| 223 | """ |
| 224 | op_type = DatastructureOperationType.ListGetAt |
| 225 | with ObservableRequestHandler(op_type, self._impl.observability_instruments) as ds_obs_handler: |
| 226 | ds_obs_handler.create_kv_span(self._impl._request_builder._collection_dtls.get_details_as_dict()) |
| 227 | kv_op_type = KeyValueOperationType.LookupIn |
| 228 | with ObservableRequestHandler(kv_op_type, self._impl.observability_instruments) as obs_handler: |
| 229 | try: |
| 230 | op = subdoc_get(f'[{index}]') |
| 231 | req, transcoder = self._impl.request_builder.build_lookup_in_request(self._key, |
| 232 | (op,), |
| 233 | obs_handler, |
| 234 | parent_span=ds_obs_handler.wrapped_span) # noqa: E501 |
| 235 | sdres: LookupInResult = self._execute_op(self._impl.lookup_in, |
| 236 | req, |
| 237 | obs_handler, |
| 238 | ds_obs_handler.wrapped_span, |
| 239 | create_type=True, |
| 240 | transcoder=transcoder) |
| 241 | return sdres.value[0].get('value', None) |
| 242 | except PathNotFoundException: |
| 243 | raise InvalidArgumentException(message=f'Index: {index} is out of range.') from None |
| 244 | |
| 245 | def remove_at(self, index: int) -> None: |
| 246 | """Removes an item at a specific index from the list. |