<commit_before>import function_type

# it shouldn't be recursive
def is_list(value):
    return _match_tuple(value, [0, 2])

def is_pack(value):
    return _match_tuple(value, [1])

def is_closure(value):
    return isinstance(value, function_type.FunctionType)

def is_nullary_closure(value):
    return is_closure(value) and not value.is_callable()

def get_type_name(value):
    name = ''
    if value is None:
        name = 'nil'
    elif isinstance(value, float):
        name = 'num'
    elif is_list(value):
        name = 'list'
    elif is_pack(value):
        name = 'pack'
    elif is_closure(value):
        name = 'closure'
    else:
        raise Exception('the unknown type {}'.format(value.__class__.__name__))

    return name

def _match_tuple(value, allowed_lengths):
    return isinstance(value, tuple) and len(value) in allowed_lengths<commit_msg>Issue #37: add a support of hash tables to type utilities<commit_after>import function_type

# it shouldn't be recursive
def is_list(value):
    return _match_tuple(value, [0, 2])

def is_pack(value):
    return _match_tuple(value, [1])

def is_closure(value):
    return isinstance(value, function_type.FunctionType)

def is_nullary_closure(value):
    return is_closure(value) and not value.is_callable()

def get_type_name(value):
    name = ''
    if value is None:
        name = 'nil'
    elif isinstance(value, float):
        name = 'num'
    elif is_list(value):
        name = 'list'
    elif isinstance(value, dict):
        name = 'hash'
    elif is_pack(value):
        name = 'pack'
    elif is_closure(value):
        name = 'closure'
    else:
        raise Exception('the unknown type {}'.format(value.__class__.__name__))

    return name

def _match_tuple(value, allowed_lengths):
    return isinstance(value, tuple) and len(value) in allowed_lengths
{'fraction_non_alphanumeric': 0.10609357997823722, 'fraction_numerical': 0.004352557127312296, 'mean_word_length': 3.4527845036319613, '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': '7114192', 'n_tokens_mistral': 588, 'n_tokens_neox': 576, 'n_words': 160}