<commit_before>import * as e from "./Enums";
import * as _ from "lodash";
import {memoize} from "./Decorators";
import {Attributes} from "./Interfaces";

export const attributesFlyweight = _.memoize(
    (attributes: Attributes): Attributes => _.clone(attributes),
    (attributes: Dictionary<any>) => {
        const ordered: Dictionary<any> = {};
        Object.keys(attributes).sort().forEach(key => ordered[key] = attributes[key]);
        return JSON.stringify(ordered);
    }
);

export default class Char {
    static empty = Char.flyweight(" ", {});

    @memoize()
    static flyweight(char: string, attributes: Attributes) {
        return new Char(char, attributesFlyweight(attributes));

    }

    constructor(private char: string, private _attributes: Attributes) {
        if (char.length !== 1) {
            throw(`Char can be created only from a single character; passed ${char.length}: ${char}`);
        }
    }

    getCharCode(): e.KeyCode {
        return (<any>e.KeyCode)[e.KeyCode[this.char.charCodeAt(0)]];
    }

    get attributes(): Attributes {
        return this._attributes;<commit_msg>Use Object.assign instead of _.clone.<commit_after>import * as e from "./Enums";
import * as _ from "lodash";
import {memoize} from "./Decorators";
import {Attributes} from "./Interfaces";

export const attributesFlyweight = _.memoize(
    (attributes: Attributes): Attributes => Object.assign({}, attributes),
    (attributes: Dictionary<any>) => {
        const ordered: Dictionary<any> = {};
        Object.keys(attributes).sort().forEach(key => ordered[key] = attributes[key]);
        return JSON.stringify(ordered);
    }
);

export default class Char {
    static empty = Char.flyweight(" ", {});

    @memoize()
    static flyweight(char: string, attributes: Attributes) {
        return new Char(char, attributesFlyweight(attributes));

    }

    constructor(private char: string, private _attributes: Attributes) {
        if (char.length !== 1) {
            throw(`Char can be created only from a single character; passed ${char.length}: ${char}`);
        }
    }

    getCharCode(): e.KeyCode {
        return (<any>e.KeyCode)[e.KeyCode[this.char.charCodeAt(0)]];
    }

    get attributes(): Attributes {
        return this._attributes;
{'fraction_non_alphanumeric': 0.14524647887323944, 'fraction_numerical': 0.0017605633802816902, 'mean_word_length': 3.2967863894139886, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '6759090', 'n_tokens_mistral': 654, 'n_tokens_neox': 634, 'n_words': 168}