src/main/php/Collectors.php
public function inGroups(callable $classifier, Collector $base = null): array
    {
        $collector = (null === $base) ? Collector::forList() : $base;
        return $this->with(
                function() { return []; },
                function(&$groups, $element) use($classifier, $collector)
                {
                    $key = $classifier($element);
                    if (!isset($groups[$key])) {
                        $groups[$key] = $collector->fork();
                    }

                    $groups[$key]->accumulate($element, $key);
                },
                function($groups)
                {
                    foreach ($groups as $key => $group) {
                        $groups[$key] = $group->finish();
                    }

                    return $groups;
                }
        );
    }
public function inGroups(callable $classifier, Collector $base = null): array
    {
        $collector = (null === $base) ? Collector::forList() : $base;
        return $this->with(
                function() { return []; },
                function(&$groups, $element) use($classifier, $collector)
                {
                    $key = $classifier($element);
                    if (!isset($groups[$key])) {
                        $groups[$key] = $collector->fork();
                    }

                    $groups[$key]->accumulate($element, $key);
                },
                function($groups)
                {
                    foreach ($groups as $key => $group) {
                        $groups[$key] = $group->finish();
                    }

                    return $groups;
                }
        );
    }
public function inGroups ( callable $ classifier , Collector $ base = null ) : array { $ collector = ( null === $ base ) ? Collector :: forList ( ) : $ base ; return $ this -> with ( function ( ) { return [ ] ; } , function ( & $ groups , $ element ) use ( $ classifier , $ collector ) { $ key = $ classifier ( $ element ) ; if ( ! isset ( $ groups [ $ key ] ) ) { $ groups [ $ key ] = $ collector -> fork ( ) ; } $ groups [ $ key ] -> accumulate ( $ element , $ key ) ; } , function ( $ groups ) { foreach ( $ groups as $ key => $ group ) { $ groups [ $ key ] = $ group -> finish ( ) ; } return $ groups ; } ) ; }
creates collector which groups the elements according to given classifier

@api
@param   callable                      $classifier  function to map elements to keys
@param   \stubbles\sequence\Collector  $base        optional  defaults to Collector::forList()
@return  array
creates collector which groups the elements according to given classifier