79140199

Date: 2024-10-30 08:21:10
Score: 1
Natty:
Report link

I wrote a small utility function:

def maybe_apply(x: T | None, f: Callable[[T], Y]) -> Y | None:
    if x is not None:
        return f(x)

Unlike decorator solution it works with library functions as well and is more explicit. Also it deduces types.

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Mihail Fufin