1. Go to this page and download the library: Download phunkie/streams library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phunkie / streams example snippets
// Stream<Pure, Int>
$stream = Stream(1, 2, 3, 4);
// Pure streams can be converted to other collections
$stream->toList(); // List<Int> (1, 2, 3, 4)
$stream->toArray(); // [1, 2, 3, 4]
port the necessary functions
// Create a stream
$stream = Stream(1, 2, 3, 4, 5);
// Process the stream
$result = $stream
->map(fn($x) => $x * 2)
->filter(fn($x) => $x > 5)
->toArray();
// Output: [6, 8, 10]
var_dump($result);
use Phunkie\Streams\IO\File\Path;
use function Phunkie\Streams\IO\File\{readFileContents, writeFileContents};
// Read file with automatic resource cleanup
$content = readFileContents(new Path('data.txt'))
->unsafeRunSync();
// Write file with guaranteed cleanup even on errors
$bytes = writeFileContents(new Path('output.txt'), "Hello, World!")
->unsafeRunSync();
use function Phunkie\Streams\IO\File\readFileContents;
// Using attempt() - returns Validation
$result = readFileContents(new Path('/nonexistent/file.txt'))
->attempt()
->unsafeRunSync();
$content = $result->getOrElse("default content");
// Using handleError() - recover from errors
$content = readFileContents(new Path('/nonexistent/file.txt'))
->handleError(fn($e) => "Error: " . $e->getMessage())
->unsafeRunSync();
use function Phunkie\Streams\IO\File\writeFile;
// Process a 10GB log file with constant ~4MB memory usage
Stream(new Path('huge-10gb-log.txt'))
->filter(fn($line) => str_contains($line, 'ERROR'))
->map(fn($line) => processLine($line))
->through(writeFile(new Path('errors.txt')));
// Process millions of records with bounded memory
Stream::fromLargeDataset()
->parMap(4, fn($record) => processRecord($record))
->chunk(1000)
->through(writeFile(new Path('output.txt')));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.