Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
qued committed Oct 4, 2023
1 parent 5517e4d commit 0184c50
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions unstructured/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0184c50

Please sign in to comment.