def select_first(condition): """ Returns first item from input sequence that satisfies `condition`. Or ``None`` if none does. >>> ['py', 'pie', 'pi'] > select_first(X.startswith('pi')) 'pie' There is also a shortcut for ``select_first(X)`` called ``first_of``: >>> first_of(['', None, 0, 3, 'something']) 3 >>> first_of([]) None """ return where(condition) | unless(StopIteration, X.next())
def select_first(condition): """ Returns first item from input sequence that satisfies `condition`. Or ``None`` if none does. >>> ['py', 'pie', 'pi'] > select_first(X.startswith('pi')) 'pie' As of ``0.2.1`` you can also :ref:`directly use regular expressions <auto-regex>` and write the above as: >>> ['py', 'pie', 'pi'] > select_first('^pi') 'pie' There is also a shortcut for ``select_first(X)`` called ``first_of``: >>> first_of(['', None, 0, 3, 'something']) 3 >>> first_of([]) None """ return where(condition) | unless(StopIteration, X.next())