sknano.core.first_true

sknano.core.first_true(iterable, default=False, pred=None)[source][source]

Returns the first true value in the iterable.

If no true value is found, returns default

If pred is not None, returns the first item for which pred(item) is true.

Parameters:

default : bool

pred : {None, callable}, optional

Examples

>>> # first_true([a,b,c], x)
>>> # a or b or c or x
>>> # first_true([a,b], x, f)
>>> # a if f(a) else b if f(b) else x