ddp_utils.utuple¶
import ddp_utils.utuple
Tuple head/tail access and non-mutating indexed replacement.
Examples
Use this public operation:
import ddp_utils.utuple
- ddp_utils.utuple.head(t: Tuple[Any, ...]) Any | None¶
Return the first item of t, or None for an empty tuple.
Parameters
Name
Type
Description
t
Tuple[Any, ...]
Input tuple; an existing None item is returned unchanged.
Returns
Type
Description
Any | None
Original first object, without copying it, or None.
Examples
Use this public operation:
result = ddp_utils.utuple.head(t=t_value)
- ddp_utils.utuple.tail(t: Tuple[Any, ...]) Tuple[Any, ...]¶
Return all items after the first as a tuple.
Parameters
Name
Type
Description
t
Tuple[Any, ...]
Input tuple, left unchanged.
Returns
Type
Description
t[1
] for at least two items; () for zero or one item.
Examples
Use this public operation:
result = ddp_utils.utuple.tail(t=t_value)
- ddp_utils.utuple.replace(t: Tuple[Any, ...], index: int, value: Any) Tuple[Any, ...]¶
Return a tuple with one indexed item replaced; do not mutate t.
Parameters
Name
Type
Description
t
Tuple[Any, ...]
Input tuple; unchanged items retain their object references.
index
int
Zero-based index; negative indexes count backward from the end.
value
Any
Replacement object, including None.
Returns
Type
Description
Tuple[Any, …]
New tuple of the same length for an integer index.
Raises
Exception
Description
IndexError
The integer index is outside the tuple, including empty input.
TypeError
The index is not accepted by Python list assignment.
Examples
Use this public operation:
result = ddp_utils.utuple.replace(t=t_value, index=index_value, value=value_value)