src/main/php/Collectors.php
public function byJoining(
            string $delimiter = ', ',
            string $prefix = '',
            string $suffix = '',
            string $keySeparator = null
    ): string {
        return $this->with(
                function () { return null; },
                function(&$joinedElements, $element, $key) use($prefix, $delimiter, $keySeparator)
                {
                    if (null === $joinedElements) {
                        $joinedElements = $prefix;
                    } else {
                        $joinedElements .= $delimiter;
                    }

                    $joinedElements .= (null !== $keySeparator ? $key . $keySeparator : null) . $element;
                },
                function($joinedElements) use($suffix) { return $joinedElements . $suffix; }
        );
    }
public function byJoining(
            string $delimiter = ', ',
            string $prefix = '',
            string $suffix = '',
            string $keySeparator = null
    ): string {
        return $this->with(
                function () { return null; },
                function(&$joinedElements, $element, $key) use($prefix, $delimiter, $keySeparator)
                {
                    if (null === $joinedElements) {
                        $joinedElements = $prefix;
                    } else {
                        $joinedElements .= $delimiter;
                    }

                    $joinedElements .= (null !== $keySeparator ? $key . $keySeparator : null) . $element;
                },
                function($joinedElements) use($suffix) { return $joinedElements . $suffix; }
        );
    }
public function byJoining ( string $ delimiter = ', ' , string $ prefix = '' , string $ suffix = '' , string $ keySeparator = null ) : string { return $ this -> with ( function ( ) { return null ; } , function ( & $ joinedElements , $ element , $ key ) use ( $ prefix , $ delimiter , $ keySeparator ) { if ( null === $ joinedElements ) { $ joinedElements = $ prefix ; } else { $ joinedElements .= $ delimiter ; } $ joinedElements .= ( null !== $ keySeparator ? $ key . $ keySeparator : null ) . $ element ; } , function ( $ joinedElements ) use ( $ suffix ) { return $ joinedElements . $ suffix ; } ) ; }
creates collector which concatenates all elements into a single string

If no key separator is provided keys will not be part of the resulting
string.
<code>
Sequence::of(['foo' => 303, 'bar' => 808, 'baz'=> 909])
->collect()
->byJoining(); // results in '303, 808, 9090'

Sequence::of(['foo' => 303, 'bar' => 808, 'baz'=> 909])
->collect()
->byJoining(', ', '', '', ': '); // results in 'foo: 303, bar: 808, baz: 9090'
</code>

@api
@param   string  $delimiter     delimiter between elements, defaults to ', '
@param   string  $prefix        optional  prefix for complete string, empty by default
@param   string  $suffix        optional  suffix for complete string, empty by default
@param   string  $keySeparator  optional  separator between key and element
@return  string
creates collector which concatenates all elements into a single string