def _filter_by_target_substances(
    substance_data, target_substances_per_property, substances_chosen_per_property
):
    """Filters substances based on whether this substance
    moves us closer towards the target number of substances
    or not.

    Parameters
    ----------
    target_substances_per_property: dict of tuple of type and SubstanceType and int
        The target number of unique substances to choose for each
        type of property of interest.
    substances_chosen_per_property: dict of tuple of type and SubstanceType and int
        The currently chosen number of unique substances which exercise
        each type of property of interest.

    Returns
    -------
    bool
        Whether to retain this substance or not.
    """

    increases_target_substance_count = False

    for property_tuple in substance_data.property_types:

        if (
            substances_chosen_per_property[property_tuple] + 1
            > target_substances_per_property[property_tuple]
        ):
            continue

        increases_target_substance_count = True
        break

    return increases_target_substance_count