<commit_before><?php

namespace Datatype;

use Datatype\Traits\PropertyMapperTrait;
use Datatype\Traits\FunctionMapperTrait;


/**
 * Collection datatype
 *
 * @property-read		integer			count		Number of elements in Collection
 * @property-read		integer			length		Alias for count
 * @property-read		integer			size		Alias for count
 * @property-read		Collection		keys		All keys in the current Collection
 * @property-read		Collection		values		All values in the current Collection
 * @property-read		mixed			first		The first item in the Collection
 * @property-read		mixed			last		The last item in the Collection
 */
class Collection extends Object implements
	\ArrayAccess,
	\SeekableIterator,
	\Countable,
	\Serializable
{
	use	PropertyMapperTrait,
		FunctionMapperTrait
		{
			FunctionMapperTrait::___process_return_value as ___t_process_return_value;
		}


	/**
	 * The collection's data is stored here
	 *
	 * @var		array
	 */
	protected $data = [];

	/**
	 * Snapshot of all the keys in the Collection when the loop started
	 *
	 * @var		array
	 */
	private $iterator_keys = [];

	/**
	 * The current key the iterator is on
	 *
	 * @var		integer|string
	 */
	private $iterator_position = 0;

	/**
	 * PropertyMapper mappings
	 *
	 * @var		array
	 */
	private static $property_map = [
		'length'		=> 'count',
		'size'			=> 'count',
		'count'			=> 'count',

		'keys'			=> 'keys',
		'values'		=> 'values',

		'first'			=> 'first',
		'last'			=> 'last',
	];

	/**
	 * FunctionMapper mappings
	 *
	 * @var		array
	 */
	private static $function_map = [
	//	Called method:		Maps to:				$data position:			Args default values:
		'unique'	=>		[ 'array_unique' ],
		'keys'		=>		[ 'array_keys' ],
		'values'	=>		[ 'array_values' ],
		'map'		=>		[ 'array_map',			2 ],
		'exists'	=>		[ 'array_key_exists',	2 ],
	];


	/**
	 * Convert non-array elements to arrays and arrays to Collections
	 *
	 * @param		mixed		Any input value
	 *
	 * @return		array		An array. If this array originally contained nested arrays, they become instances of Collection
	 */
	private function to_c( $items )
	{
		$data = [];

		// Ensure we are dealing with arrays all the time
		$items = (array)$items;

		foreach ( $items as $key => &$value )
		{
			if ( is_array( $value ) ) $items[$key] = new Collection( $value );
		}

		return $items;
	}

	/**
	 * Get the Collection's keys
	 *
	 * @return		self		A Collection containing all the keys
	 */
	protected function keys()
	{
		return $this->___call_function_from_map( 'keys', $this->data );
	}

	/**
	 * Get the Collection's values
	 *
	 * @return		self		A Collection containing all the values
	 */
	protected function values()
	{
		return $this->___call_function_from_map( 'values', $this->data );
	}

	/**
	 * Get the first item in the Collection
	 *
	 * @return		mixed		The first item in the Collection
	 */
	protected function first()
	{
		return reset( $this->data );
	}

	/**
	 * Get the last item in the Collection
	 *
	 * @return		mixed		The last item in the Collection
	 */
	protected function last()
	{
		return end( $this->data );
	}


	/**
	 * Create a new instance of the class
	 *
	 * @param		array		The data this instance should hold
	 */
	public function __construct( $array = [] )
	{
		// If the provided array contains nested arrays, they should become Collections, too
		$this->data = $this->to_c( $array );<commit_msg>Do not break the chain, you never know what your parents do<commit_after><?php

namespace Datatype;

use Datatype\Traits\PropertyMapperTrait;
use Datatype\Traits\FunctionMapperTrait;


/**
 * Collection datatype
 *
 * @property-read		integer			count		Number of elements in Collection
 * @property-read		integer			length		Alias for count
 * @property-read		integer			size		Alias for count
 * @property-read		Collection		keys		All keys in the current Collection
 * @property-read		Collection		values		All values in the current Collection
 * @property-read		mixed			first		The first item in the Collection
 * @property-read		mixed			last		The last item in the Collection
 */
class Collection extends Object implements
	\ArrayAccess,
	\SeekableIterator,
	\Countable,
	\Serializable
{
	use	PropertyMapperTrait,
		FunctionMapperTrait
		{
			FunctionMapperTrait::___process_return_value as ___t_process_return_value;
		}


	/**
	 * The collection's data is stored here
	 *
	 * @var		array
	 */
	protected $data = [];

	/**
	 * Snapshot of all the keys in the Collection when the loop started
	 *
	 * @var		array
	 */
	private $iterator_keys = [];

	/**
	 * The current key the iterator is on
	 *
	 * @var		integer|string
	 */
	private $iterator_position = 0;

	/**
	 * PropertyMapper mappings
	 *
	 * @var		array
	 */
	private static $property_map = [
		'length'		=> 'count',
		'size'			=> 'count',
		'count'			=> 'count',

		'keys'			=> 'keys',
		'values'		=> 'values',

		'first'			=> 'first',
		'last'			=> 'last',
	];

	/**
	 * FunctionMapper mappings
	 *
	 * @var		array
	 */
	private static $function_map = [
	//	Called method:		Maps to:				$data position:			Args default values:
		'unique'	=>		[ 'array_unique' ],
		'keys'		=>		[ 'array_keys' ],
		'values'	=>		[ 'array_values' ],
		'map'		=>		[ 'array_map',			2 ],
		'exists'	=>		[ 'array_key_exists',	2 ],
	];


	/**
	 * Convert non-array elements to arrays and arrays to Collections
	 *
	 * @param		mixed		Any input value
	 *
	 * @return		array		An array. If this array originally contained nested arrays, they become instances of Collection
	 */
	private function to_c( $items )
	{
		$data = [];

		// Ensure we are dealing with arrays all the time
		$items = (array)$items;

		foreach ( $items as $key => &$value )
		{
			if ( is_array( $value ) ) $items[$key] = new Collection( $value );
		}

		return $items;
	}

	/**
	 * Get the Collection's keys
	 *
	 * @return		self		A Collection containing all the keys
	 */
	protected function keys()
	{
		return $this->___call_function_from_map( 'keys', $this->data );
	}

	/**
	 * Get the Collection's values
	 *
	 * @return		self		A Collection containing all the values
	 */
	protected function values()
	{
		return $this->___call_function_from_map( 'values', $this->data );
	}

	/**
	 * Get the first item in the Collection
	 *
	 * @return		mixed		The first item in the Collection
	 */
	protected function first()
	{
		return reset( $this->data );
	}

	/**
	 * Get the last item in the Collection
	 *
	 * @return		mixed		The last item in the Collection
	 */
	protected function last()
	{
		return end( $this->data );
	}


	/**
	 * Create a new instance of the class
	 *
	 * @param		array		The data this instance should hold
	 */
	public function __construct( $array = [] )
	{
		parent::__construct();

		// If the provided array contains nested arrays, they should become Collections, too
		$this->data = $this->to_c( $array );
{'fraction_non_alphanumeric': 0.12090828664110882, 'fraction_numerical': 0.0008846947803007962, 'mean_word_length': 3.0183649289099526, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '80752', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2203, 'n_words': 694}