Skip to content

Instantly share code, notes, and snippets.

@Harduim
Last active December 26, 2022 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Harduim/ed5cfdec42e9eb551fc3619fbce8d359 to your computer and use it in GitHub Desktop.
Save Harduim/ed5cfdec42e9eb551fc3619fbce8d359 to your computer and use it in GitHub Desktop.
from typing import Iterable, TypeVar
T = TypeVar("T")
def first(items: Iterable[T], pred: callable) -> T | None:
return next((i for i in items if pred(i)), None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment