<commit_before><?php

namespace SebastiaanLuca\Helpers\Collections;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider;

class CollectionHelperServiceProvider extends ServiceProvider
{
    /**
     * Boot all collection macros.
     */
    protected function bootMacros()
    {
        // Create Carbon instances from items in a collection
        Collection::macro('carbonize', function() {
            return collect($this->items)->map(function($time) {
                if (empty($time)) {
                    return null;
                }
                
                return new Carbon($time);
            });
        });
        
        // Reduce the collection to only include strings found between another start and end string
        Collection::macro('between', function($start, $end) {
            return collect($this->items)->reduce(function($items, $method) use ($start, $end) {
                if (preg_match('/^' . $start . '(.*)' . $end . '$/', $method, $matches)) {
                    $items[] = $matches[1];
                }
                
                return collect($items);
            });
        });
        
        // Return
        Collection::macro('methodize', function($method) {
            return collect($this->items)->map(function($item) use($method){
                return call_user_func($method, $item);
            });
        });
    }
    
    /**
     * Register the service provider.
     */
    public function register()
    {
        //
    }
    
    /**
     * Boot the service provider.<commit_msg>Add new collection macros<commit_after><?php

namespace SebastiaanLuca\Helpers\Collections;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider;

class CollectionHelperServiceProvider extends ServiceProvider
{
    /**
     * Boot all collection macros.
     */
    protected function bootMacros()
    {
        // Create Carbon instances from items in a collection
        Collection::macro('carbonize', function() {
            return collect($this->items)->map(function($time) {
                if (empty($time)) {
                    return null;
                }
                
                return new Carbon($time);
            });
        });
        
        // Reduce the collection to only include strings found between another start and end string
        Collection::macro('between', function($start, $end) {
            return collect($this->items)->reduce(function($items, $method) use ($start, $end) {
                if (preg_match('/^' . $start . '(.*)' . $end . '$/', $method, $matches)) {
                    $items[] = $matches[1];
                }
                
                return collect($items);
            });
        });
        
        // Return
        Collection::macro('methodize', function($method) {
            return collect($this->items)->map(function($item) use($method){
                return call_user_func($method, $item);
            });
        });
    
        // Fixed in Laravel 5.4
        Collection::macro('mapWithIntegerKeys', function($callback) {
            $result = [];
        
            foreach ($this->items as $key => $value) {
                $assoc = $callback($value, $key);
            
                foreach ($assoc as $mapKey => $mapValue) {
                    $result[$mapKey] = $mapValue;
                }
            }
        
            return new static($result);
        });
    
        Collection::macro('d', function() {
            d($this);
        
            return $this;
        });
    
        Collection::macro('ddd', function() {
            ddd($this);
        });
    
        Collection::macro('transformKeys', function(callable $operation) {
            return collect($this->items)->mapWithKeys(function($item, $key) use ($operation) {
                return [$operation($key) => $item];
            });
        });
    }
    
    /**
     * Register the service provider.
     */
    public function register()
    {
        //
    }
    
    /**
     * Boot the service provider.
{'fraction_non_alphanumeric': 0.13352685050798258, 'fraction_numerical': 0.0009675858732462506, 'mean_word_length': 1.5973618090452262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2136041', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1017, 'n_words': 230}