From 0184c50eb066a2a99066186fb8ec511a1ace422f Mon Sep 17 00:00:00 2001 From: Alan Bertl Date: Wed, 4 Oct 2023 17:18:36 -0500 Subject: [PATCH] Add docstrings --- unstructured/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unstructured/utils.py b/unstructured/utils.py index 9cff97d955..52ec2c1021 100644 --- a/unstructured/utils.py +++ b/unstructured/utils.py @@ -217,11 +217,14 @@ def _first_and_remaining_iterator(it: Iterable) -> Tuple[Any, Iterator]: def first(it: Iterable) -> Any: + """Returns the first item from an iterable. Raises an error if the iterable is empty.""" out, _ = _first_and_remaining_iterator(it) return out def only(it: Iterable) -> Any: + """Returns the only element from a singleton iterable. Raises an error if the iterable is not a + singleton.""" out, iterator = _first_and_remaining_iterator(it) if any(True for _ in iterator): raise ValueError(