<commit_before><?php

namespace TightenCo\Jigsaw\Collection;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection as BaseCollection;
use TightenCo\Jigsaw\IterableObject;

class Collection extends BaseCollection
{
    public $settings;
    public $name;

    public static function withSettings(IterableObject $settings, $name)
    {
        $collection = new static();
        $collection->settings = $settings;
        $collection->name = $name;

        return $collection;
    }

    public function loadItems(BaseCollection $items)
    {
        $sortedItems = $this
            ->defaultSort($items)
            ->filter($this->getFilter())
            ->map($this->getMap())
            ->keyBy(function ($item) {
                return $item->getFilename();
            });

        return $this->updateItems($this->addAdjacentItems($sortedItems));
    }

    public function updateItems(BaseCollection $items)
    {
        $this->items = $this->getArrayableItems($items);

        return $this;
    }

    private function addAdjacentItems(BaseCollection $items)
    {
        $count = $items->count();
        $adjacentItems = $items->map(function ($item) {
            return $item->getFilename();
        });
        $previousItems = $adjacentItems->prepend(null)->take($count);
        $nextItems = $adjacentItems->push(null)->take(-$count);

        return $items->each(function ($item) use ($previousItems, $nextItems) {<commit_msg>Run collection item filter after mapping<commit_after><?php

namespace TightenCo\Jigsaw\Collection;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection as BaseCollection;
use TightenCo\Jigsaw\IterableObject;

class Collection extends BaseCollection
{
    public $settings;
    public $name;

    public static function withSettings(IterableObject $settings, $name)
    {
        $collection = new static();
        $collection->settings = $settings;
        $collection->name = $name;

        return $collection;
    }

    public function loadItems(BaseCollection $items)
    {
        $sortedItems = $this
            ->defaultSort($items)
            ->map($this->getMap())
            ->filter($this->getFilter())
            ->keyBy(function ($item) {
                return $item->getFilename();
            });

        return $this->updateItems($this->addAdjacentItems($sortedItems));
    }

    public function updateItems(BaseCollection $items)
    {
        $this->items = $this->getArrayableItems($items);

        return $this;
    }

    private function addAdjacentItems(BaseCollection $items)
    {
        $count = $items->count();
        $adjacentItems = $items->map(function ($item) {
            return $item->getFilename();
        });
        $previousItems = $adjacentItems->prepend(null)->take($count);
        $nextItems = $adjacentItems->push(null)->take(-$count);

        return $items->each(function ($item) use ($previousItems, $nextItems) {
{'fraction_non_alphanumeric': 0.13279406808223795, 'fraction_numerical': 0.0, 'mean_word_length': 2.738035264483627, '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': '2109258', 'n_tokens_mistral': 826, 'n_tokens_neox': 815, 'n_words': 165}