From c8d01cc5e8083a6586ae61a6c3371d7ed2428f6a Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Sun, 19 Sep 2021 19:27:29 -0700 Subject: [PATCH] feat(FastAPI): add aurweb.util.apply_all(iterable, fn) A helper which allows us to apply a specific function to each item in an iterable. Signed-off-by: Kevin Morris --- aurweb/util.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/aurweb/util.py b/aurweb/util.py index 08e6d7c6..44f711f1 100644 --- a/aurweb/util.py +++ b/aurweb/util.py @@ -7,7 +7,7 @@ import secrets import string from datetime import datetime -from typing import Any, Dict +from typing import Any, Callable, Dict, Iterable from urllib.parse import urlencode, urlparse from zoneinfo import ZoneInfo @@ -167,3 +167,8 @@ def add_samesite_fields(response: Response, value: str): def get_ssh_fingerprints(): return aurweb.config.get_section("fingerprints") or {} + + +def apply_all(iterable: Iterable, fn: Callable): + for item in iterable: + fn(item)