Skip to content

Instantly share code, notes, and snippets.

@pilcrow
Created September 6, 2020 14:03
Show Gist options
  • Save pilcrow/449d6936525377181f875a828f2f9462 to your computer and use it in GitHub Desktop.
Save pilcrow/449d6936525377181f875a828f2f9462 to your computer and use it in GitHub Desktop.
def coalesce(*args):
# return first(lambda x: x is not None, args)
return next(_ for _ in args if _ is not None)
def first(selector, iterable, default = None):
return next((_ for _ in iterable if selector(_)), default)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment