<commit_before>import {Pair, Mapping, reduce} from 'tsfun';


export type Tree<T> = Pair<T /* ITEM */, Treelist<T> /* CHILDREN */>;

export type Treelist<T> = Array<Tree<T>>;


export module Treelist {

    export module Tree {

        export const ITEM = 0;
        export const CHILDREN = 1;
    }
}


export function mapTreelist<A,B>(f: Mapping<A,B>, t: Treelist<A>): Treelist<B>;
export function mapTreelist<A,B>(f: Mapping<A,B>): Mapping<Treelist<A>,Treelist<B>>;
export function mapTreelist(...args: any[]): any {

    const inner = (f: any) => (t: any) => {

        const replacement = [];
        for (let [node,tree] of t) {
            replacement.push([f(node),mapTreelist(f,tree)]);
        }
        return replacement;
    }

    return args.length === 2
        ? inner(args[0])(args[1])
        : inner(args[0])
}


export function mapLeafs<A>(f: Mapping<Treelist<A>>, t: Treelist<A>): Treelist<A> {

    return f(t).map(([node,leafs]) => [node,mapLeafs(f, leafs)]);
}


export function flattenTreelist<A>(t: Treelist<A>): Array<A> {

    return t.reduce((tree, [a, children]) =>
         tree.concat([a]).concat(flattenTreelist(children)), []);
}
<commit_msg>Rename variable<commit_after>import {Pair, Mapping, reduce} from 'tsfun';


export type Tree<T> = Pair<T /* ITEM */, Treelist<T> /* CHILDREN */>;

export type Treelist<T> = Array<Tree<T>>;


export module Treelist {

    export module Tree {

        export const ITEM = 0;
        export const CHILDREN = 1;
    }
}


export function mapTreelist<A,B>(f: Mapping<A,B>, t: Treelist<A>): Treelist<B>;
export function mapTreelist<A,B>(f: Mapping<A,B>): Mapping<Treelist<A>,Treelist<B>>;
export function mapTreelist(...args: any[]): any {

    const inner = (f: any) => (t: any) => {

        const replacement = [];
        for (let [node,tree] of t) {
            replacement.push([f(node),mapTreelist(f,tree)]);
        }
        return replacement;
    }

    return args.length === 2
        ? inner(args[0])(args[1])
        : inner(args[0])
}


export function mapLeafs<A>(f: Mapping<Treelist<A>>, t: Treelist<A>): Treelist<A> {

    return f(t).map(([node,leafs]) => [node,mapLeafs(f, leafs)]);
}


export function flattenTreelist<A>(t: Treelist<A>): Array<A> {

    return t.reduce((as, [a, children]) =>
         as.concat([a]).concat(flattenTreelist(children)), []);
}

{'fraction_non_alphanumeric': 0.18521665250637212, 'fraction_numerical': 0.005097706032285472, 'mean_word_length': 3.3936567164179103, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 57, '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': '5202018', 'n_tokens_mistral': 929, 'n_tokens_neox': 842, 'n_words': 181}