| @@ 50-61 (lines=12) @@ | ||
| 47 | * |
|
| 48 | * @return StreamInterface<self> |
|
| 49 | */ |
|
| 50 | public function split(string $delimiter = null): StreamInterface |
|
| 51 | { |
|
| 52 | $parts = empty($delimiter) ? |
|
| 53 | str_split($this->value) : explode($delimiter, $this->value); |
|
| 54 | $stream = new Stream(self::class); |
|
| 55 | ||
| 56 | foreach ($parts as $part) { |
|
| 57 | $stream = $stream->add(new self($part)); |
|
| 58 | } |
|
| 59 | ||
| 60 | return $stream; |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Returns a collection of the string splitted by the given chunk size |
|
| @@ 58-72 (lines=15) @@ | ||
| 55 | * |
|
| 56 | * @return TypedCollectionInterface |
|
| 57 | */ |
|
| 58 | public function split(string $delimiter = null): TypedCollectionInterface |
|
| 59 | { |
|
| 60 | $parts = empty($delimiter) ? |
|
| 61 | str_split($this->value) : explode($delimiter, $this->value); |
|
| 62 | $strings = []; |
|
| 63 | ||
| 64 | foreach ($parts as $part) { |
|
| 65 | $strings[] = new self($part); |
|
| 66 | } |
|
| 67 | ||
| 68 | return new TypedCollection( |
|
| 69 | self::class, |
|
| 70 | $strings |
|
| 71 | ); |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * Returns a collection of the string splitted by the given chunk size |
|