<commit_before><?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

class Math_Formula_Function_Coalesce extends Math_Formula_Function
{
	function evaluate( $element )
	{
		foreach ( $element as $child ) {
			$value = $this->evaluateChild($child);

			if (! empty($value)) {
				return $value;
			}
		}

		return 0;
	}
}

<commit_msg>[ENH] make coalesce math function work with for-each returning array of values<commit_after><?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

class Math_Formula_Function_Coalesce extends Math_Formula_Function
{
	function evaluate( $element )
	{
		foreach ( $element as $child ) {
			$value = $this->evaluateChild($child);

			if (is_array($value)) {
				foreach ($value as $val) {
					if (! empty($val)) {
						return $val;
					}
				}
			}

			if (! empty($value)) {
				return $value;
			}
		}

		return 0;
	}
}


{'fraction_non_alphanumeric': 0.11206225680933853, 'fraction_numerical': 0.014007782101167316, 'mean_word_length': 3.2442244224422443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4729047', 'n_tokens_mistral': 478, 'n_tokens_neox': 396, 'n_words': 137}