macpie.itertools.filter_get_message#

macpie.itertools.filter_get_message(predicates, iterable, only_first=False)#

Make an iterator from items of iterable for which one or more predicates returns true, along with the index of that item and optional message information.

Returns an iterator of tuples of length 3, where the first value is the item that returned true, second value is the index of that item, and the third value is the corresponding object in meta if specified, otherwise it is the predicate function itself.

>>> seq = [1, "asdf", 3, None, "a", 5]
>>> valid_values = filter_get_message(lambda x: isinstance(x, int), seq)
>>> next(nums)
(3, 2)
Parameters:
  • predicates – a list of Boolean-valued functions

  • iterable

  • meta – a list of objects parallel to predicates, where if a predicate returns true, the corresponding object in this iterable will also be returned in the return tuple. If the meta iterable is longer than the predicates iterable, meta will be truncated; if meta is shorter than predicates,

  • only_first – Boolean indicating whether to constrain results to the first predicate that returns true. Each item only matches predicate once