Coverage for src/remedapy/only.py: 100%

1 from collections.abc import Callable, Sequence

2 from typing import TypeVar, overload

3

4 T = TypeVar('T')

5

6

7@overload

8 def only() -> Callable[[Sequence[T]], T | None]: ...

9

10

11@overload

12 def only(array: Sequence[T], /) -> T | None: ...

13

14

15 def only(array: Sequence[T] | None = None, /) -> T | None | Callable[[Sequence[T]], T | None]:

16 if array is None:

17 return only

18 return array[0] if len(array) == 1 else None