<commit_before>"""
Contains generic helper funcitons to aid in parsing.
"""

import itertools


def take_while(predicate, items):
    return list(itertools.takewhile(predicate, items))


def drop_while(predicate, items):
    return list(itertools.dropwhile(predicate, items))


def not_(func):
    return lambda *args, **kwargs: not func(*args, **kwargs)


def first(predicate, iterable):
    for item in iterable:
        if predicate(item):
            return item
    return None


def rfirst(predicate, iterable):
    return first(predicate, reversed(list(iterable)))


def catch(func, *args, **kwargs):
    """
    Executes `func` with `args` and `kwargs` as arguments. If `func` throws an error, this function
    returns the error, otherwise it returns `None`.
    """
    try:
        func(*args, **kwargs)
    except Exception as error:
        return error<commit_msg>Return None explicitly instead of implicitly<commit_after>"""
Contains generic helper funcitons to aid in parsing.
"""

import itertools


def take_while(predicate, items):
    return list(itertools.takewhile(predicate, items))


def drop_while(predicate, items):
    return list(itertools.dropwhile(predicate, items))


def not_(func):
    return lambda *args, **kwargs: not func(*args, **kwargs)


def first(predicate, iterable):
    for item in iterable:
        if predicate(item):
            return item
    return None


def rfirst(predicate, iterable):
    return first(predicate, reversed(list(iterable)))


def catch(func, *args, **kwargs):
    """
    Executes `func` with `args` and `kwargs` as arguments. If `func` throws an error, this function
    returns the error, otherwise it returns `None`.
    """
    try:
        func(*args, **kwargs)
    except Exception as error:
        return error
    return None
{'fraction_non_alphanumeric': 0.10981697171381032, 'fraction_numerical': 0.0, 'mean_word_length': 3.6020408163265305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3069910', 'n_tokens_mistral': 535, 'n_tokens_neox': 521, 'n_words': 178}