Created
March 4, 2023 00:35
-
-
Save sjkillen/3f04ea89103e82dfebdc8dd98cc382d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import singledispatch, wraps | |
from collections.abc import Iterable | |
def one_or_many(fn): | |
@wraps(fn) | |
@singledispatch | |
def wrapper(*args, **kwargs): | |
fn(*args, **kwargs) | |
@wrapper.register | |
def _(items: Iterable, *args, **kwargs): | |
for item in items: | |
wrapper(item, *args, **kwargs) | |
return wrapper | |
@one_or_many | |
def print_fancy(item): | |
print(f">>>>>>>>{item}<<<<<<<<") | |
print_fancy(1) | |
print_fancy([2, 3, 4]) | |
print_fancy([[[[[[[[[5, 6, 7, 8]]]]]]]]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment