<commit_before>/**
 *
 */
import {Map, List} from 'immutable';
import reduce from 'lodash/collection/reduce';



/**
 *
 */
export default class Response {

	constructor(props = Map(), errors = List()) {
		this.props = props;
		this.errors = errors;
	}

	has(key) {
		return this.props.has(key);
	}

	count(key) {
		return this.all(key).length
	}

	get(key) {
		return this.first(key);
	}

	first(key, missing) {
		const all = this.all(key);

		return all.length
			? all[0]
			: missing;
	}

	all(key) {
		return this.props.get(key, []);
	}

	withProp(key, value) {
		const values = this.all(key);

		return new Response(
			this.props.set(key, values.concat(value)),
			this.errors
		);
	}

	withProps(props) {
		return reduce(props, (self, value, key) => {
			return self.withProp(key, value);
		}, this);
	}

	withError(error) {
		return new Response(
			this.props,
			this.errors.push(error)
		);
	}
}
<commit_msg>Added a way to get groups of properties<commit_after>/**
 *
 */
import {Map, List} from 'immutable';
import reduce from 'lodash/collection/reduce';



/**
 *
 */
export default class Response {

	constructor(props = Map(), errors = List()) {
		this.props = props;
		this.errors = errors;
	}

	has(key) {
		return this.props.has(key);
	}

	count(key) {
		return this.all(key).length
	}

	get(key) {
		return this.first(key);
	}

	first(key, missing) {
		const all = this.all(key);

		return all.length
			? all[0]
			: missing;
	}

	all(key) {
		return this.props.get(key, []);
	}

	groups(...keys) {
		const groups = [];

		keys.forEach((key) => {
			this.all(key).forEach((value, i) => {
				if (!groups[i]) {
					groups[i] = {};
				}

				groups[i][key] = value;
			});
		});

		return groups;
	}

	withProp(key, value) {
		const values = this.all(key);

		return new Response(
			this.props.set(key, values.concat(value)),
			this.errors
		);
	}

	withProps(props) {
		return reduce(props, (res, value, key) => {
			return res.withProp(key, value);
		}, this);
	}

	withError(error) {
		return new Response(
			this.props,
			this.errors.push(error)
		);
	}
}

{'fraction_non_alphanumeric': 0.17601918465227817, 'fraction_numerical': 0.0009592326139088729, 'mean_word_length': 2.988527724665392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7009148', 'n_tokens_mistral': 890, 'n_tokens_neox': 780, 'n_words': 160}