<commit_before>///
// Dependencies
///

import { fromJS } from 'immutable';
import isArray from 'lodash/isArray';
import first from 'lodash/first';
import tail from 'lodash/tail';


///
// Constants
///

const ARRAY_INDICATOR = [];


///
// Functions
///

const isArrayIndicator = item => (
	isArray(item) && item.length < 1
);

const addMeta = (state, pathDescriptor, keyPath=[]) => {
	if(! isArray(pathDescriptor)) {
		throw new Error('pathDescriptor must be an array');
	}

	if(pathDescriptor.length < 1) {
		return state.set('_meta', fromJS({keyPath: keyPath}));
	}

	const key = first(pathDescriptor);

	if(isArrayIndicator(key)) {
		return state.map((item, itemKey) => (
			addMeta(
				item,
				tail(pathDescriptor),
				keyPath.concat([itemKey])
			)<commit_msg>Added defensive return to addMeta<commit_after>///
// Dependencies
///

import { fromJS } from 'immutable';
import isArray from 'lodash/isArray';
import isUndefined from 'lodash/isUndefined';
import first from 'lodash/first';
import tail from 'lodash/tail';


///
// Constants
///

const ARRAY_INDICATOR = [];


///
// Functions
///

const isArrayIndicator = item => (
	isArray(item) && item.length < 1
);

const addMeta = (state, pathDescriptor, keyPath=[]) => {
	if(! isArray(pathDescriptor)) {
		throw new Error('pathDescriptor must be an array');
	}

	if(isUndefined(state)) {
		return state;
	}

	if(pathDescriptor.length < 1) {
		return state.set('_meta', fromJS({keyPath: keyPath}));
	}

	const key = first(pathDescriptor);

	if(isArrayIndicator(key)) {
		return state.map((item, itemKey) => (
			addMeta(
				item,
				tail(pathDescriptor),
				keyPath.concat([itemKey])
			)
{'fraction_non_alphanumeric': 0.1626360338573156, 'fraction_numerical': 0.0024183796856106408, 'mean_word_length': 3.7832369942196533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '576021', 'n_tokens_mistral': 604, 'n_tokens_neox': 555, 'n_words': 129}