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

1 from collections.abc import Callable

2 from typing import Any, TypeVar, cast, overload

3

4 T = TypeVar('T')

5

6

7@overload

8 def tap(fn: Callable[[T], Any], /) -> Callable[[T], T]: ...

9

10

11@overload

12 def tap(value: T, fn: Callable[[T], Any], /) -> T: ...

13

14

15 def tap(value: T | Callable[[T], Any], fn: Callable[[T], Any] | None = None, /) -> T | Callable[[T], T]:

16 if fn is None:

17 return lambda x: tap(x, cast(Callable[[T], Any], value))

18 fn(cast(T, value))

19 return value