<commit_before><?php

namespace Vulcan\Collections;

use ArrayAccess;
use ArrayIterator;
use Countable;
use IteratorAggregate;
use Vulcan\Collections\Support\Arr;
use Vulcan\Collections\Contracts\Collection as CollectionContract;

class Collection implements CollectionContract, ArrayAccess, Countable, IteratorAggregate
{
    /**
     * Items of the collection.
     *
     * @var array
     */
    protected $items = [];

    /**
     * Create a new collection instance.
     *
     * @param  mixed  $items
     */
    public function __construct($items)
    {
        $this->items = Arr::transmute($items);
    }

    /**
     * Helper static method to easily create a new Collection instance.
     *
     * @param  mixed  $items;
     * @return self
     */
    public static function make($items)
    {
        return new static($items);
    }

    /**
     * Returns an external iterator.
     *
     * @return void
     */
    public function getIterator()
    {
        return new ArrayIterator($this->items);
    }

    /**
     * Retrieve all the items from the collection.
     *
     * @return array
     */
    public function all()
    {
        return $this->items;
    }

    /**
     * Get the specified item from the collection.
     *
     * @param  mixed  $key
     * @return mixed
     */
    public function get($key)
    {
        return Arr::get($this->items, $key);
    }

    /**
     * Push an item to the collection.
     *
     * @param  mixed  $value
     */
    public function push($value)
    {
        return $this->itemSet($value);
    }

    /**
     * Put the specified item in the collection with the given key.
     *
     * @param  mixed  $key
     * @param  mixed  $value
     */
    public function put($key, $value)
    {
        return $this->itemSet($value, $key);
    }

    /**
     * Remove the given item from the collection.
     *
     * @param  mixed  $key
     */
    public function remove($key)
    {
        return $this->itemUnset($key);
    }

    /**
     * Determine if the given item exists in the collection.
     *
     * @param  mixed  $key
     */
    public function exists($key)
    {
        return $this->itemExists($key);
    }

    /**
     * Return the number of items in the collection.
     */
    public function count()
    {
        return count($this->items);
    }

    /**
     * Return the first item from the collection.
     *
     * @return mixed
     */
    public function first()
    {
        return $this->itemFirst();
    }

    /**
     * Return the last item from the collection.
     *
     * @return mixed
     */
    public function last()
    {
        return $this->itemLast();
    }

    /**
     * Loop through the items with the defined callback.
     *
     * @param  callable  $callable
     * @return void
     */
    public function each(callable $callable)
    {
        foreach ($this->items as $key => $item) {
            $callable($item, $key);
        }

        return $this;
    }

    /**
     * Apply the callable to the collection items.
     *
     * @param  callable  $callable
     * @return self
     */
    public function map(callable $callable)
    {
        $keys    = array_keys($this->items);
        $results = array_map($callable, $this->items, $keys);

        return new self($results);
    }

    /**
     * Filter the collection items through the callable.<commit_msg>Break from each if callback returns false<commit_after><?php

namespace Vulcan\Collections;

use ArrayAccess;
use ArrayIterator;
use Countable;
use IteratorAggregate;
use Vulcan\Collections\Support\Arr;
use Vulcan\Collections\Contracts\Collection as CollectionContract;

class Collection implements CollectionContract, ArrayAccess, Countable, IteratorAggregate
{
    /**
     * Items of the collection.
     *
     * @var array
     */
    protected $items = [];

    /**
     * Create a new collection instance.
     *
     * @param  mixed  $items
     */
    public function __construct($items)
    {
        $this->items = Arr::transmute($items);
    }

    /**
     * Helper static method to easily create a new Collection instance.
     *
     * @param  mixed  $items;
     * @return self
     */
    public static function make($items)
    {
        return new static($items);
    }

    /**
     * Returns an external iterator.
     *
     * @return void
     */
    public function getIterator()
    {
        return new ArrayIterator($this->items);
    }

    /**
     * Retrieve all the items from the collection.
     *
     * @return array
     */
    public function all()
    {
        return $this->items;
    }

    /**
     * Get the specified item from the collection.
     *
     * @param  mixed  $key
     * @return mixed
     */
    public function get($key)
    {
        return Arr::get($this->items, $key);
    }

    /**
     * Push an item to the collection.
     *
     * @param  mixed  $value
     */
    public function push($value)
    {
        return $this->itemSet($value);
    }

    /**
     * Put the specified item in the collection with the given key.
     *
     * @param  mixed  $key
     * @param  mixed  $value
     */
    public function put($key, $value)
    {
        return $this->itemSet($value, $key);
    }

    /**
     * Remove the given item from the collection.
     *
     * @param  mixed  $key
     */
    public function remove($key)
    {
        return $this->itemUnset($key);
    }

    /**
     * Determine if the given item exists in the collection.
     *
     * @param  mixed  $key
     */
    public function exists($key)
    {
        return $this->itemExists($key);
    }

    /**
     * Return the number of items in the collection.
     */
    public function count()
    {
        return count($this->items);
    }

    /**
     * Return the first item from the collection.
     *
     * @return mixed
     */
    public function first()
    {
        return $this->itemFirst();
    }

    /**
     * Return the last item from the collection.
     *
     * @return mixed
     */
    public function last()
    {
        return $this->itemLast();
    }

    /**
     * Loop through the items with the defined callback.
     *
     * @param  callable  $callable
     * @return void
     */
    public function each(callable $callable)
    {
        foreach ($this->items as $key => $item) {
            if ($callback($item, $key) === false) {
                break;
            }
        }

        return $this;
    }

    /**
     * Apply the callable to the collection items.
     *
     * @param  callable  $callable
     * @return self
     */
    public function map(callable $callable)
    {
        $keys    = array_keys($this->items);
        $results = array_map($callable, $this->items, $keys);

        return new self($results);
    }

    /**
     * Filter the collection items through the callable.
{'fraction_non_alphanumeric': 0.11556912341910161, 'fraction_numerical': 0.0, 'mean_word_length': 1.7753126260588947, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1412627', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1980, 'n_words': 568}