Skip to content

Commit

Permalink
Extract a 'starfilter', similar to itertools.starmap, to generalize t…
Browse files Browse the repository at this point in the history
…he concept of filtering results over a sequence of tuples.
  • Loading branch information
jaraco committed Nov 4, 2023
1 parent 131eff7 commit 4d82dc4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions distutils/dep_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def newer(source, target):
return _newer(source, target)


def _starfilter(pred, iterables):
"""
Like itertools.starmap but for filter.
"""
return filter(lambda x: pred(*x), iterables)


def newer_pairwise(sources, targets):
"""
Filter filenames where sources are newer than targets.
Expand All @@ -36,11 +43,7 @@ def newer_pairwise(sources, targets):
targets) where source is newer than target, according to the semantics
of 'newer()'.
"""

def newer_pair(pair):
return newer(*pair)

newer_pairs = filter(newer_pair, zip_strict(sources, targets))
newer_pairs = _starfilter(newer, zip_strict(sources, targets))
return tuple(map(list, zip(*newer_pairs)))


Expand Down

0 comments on commit 4d82dc4

Please sign in to comment.