poros
8/30/2018 - 9:54 AM

Search/First match generator

Return the first match for a condition without going through the whole list using a generator, because expressions

next((x for x in xs if x.y == 10), None)

# equivalent to

for x in xs:
  if x.y ==10:
    return x
    
# if there are side effects, they get executed since it goes through the list until the first match