New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable fluent interface for streams #109
Comments
Another solution is to just write: $stream = Stream\filter($stream, $filterFunctor);
$stream = Stream\map($stream, $mapFunctor);
$stream = Stream\filter($stream, $otherFilterFunctor); But I agree, chaining can be a bit nicer to read. Unfortunately such functionality can only be implemented by adding the to be chained methods to each and every implementation, mixing responsibilities. |
What could be done is using a wrapper, e.g. $output = transform($stream)
->filter(...)
->map(...); where |
My suggestion is to only add a single
|
How would the API of a |
That's the tricky part! |
@joshdifabio Your comment was right, but without the leading |
Ah, you already have an async iterator! interface Transform
{
function apply($value): Iterator;
} So the |
@joshdifabio We have the following options: $stream = $stream->apply($a)->apply($b); $stream = transform($stream)->apply($a)->apply($b); $stream = transform($stream)->filter($a)->map($b); The first one requires an additional method and violates single responsibility. The second one allows custom transforms, the third one is more expressive, but doesn't allow custom transforms. |
I like the first option the most. The second is okay too but it hides the functionality from users since the One of the nice things about the $stream = $stream->apply(chunkStream())
->apply($gzipAlgo->compressStream())
->apply($cryptAlgo->encryptStream()); |
I guess we should move this issue to |
This applies to both |
This allows chaining transformations. Closes #109.
Closing for now, we might revisit it at a later time. It can always be added, as the feature is self-contained. See #136. |
Add warning about locally closed resources being undefined behavior
The stream functions suffer from the same problems as PHP's array functions; they're awkward to chain.
This would be preferable imo:
Edit: Inspired by apache beam.
The text was updated successfully, but these errors were encountered: