1: <?php declare(strict_types=1);
2:
3: namespace Salient\Contract\Core\Pipeline;
4:
5: use Closure;
6:
7: /**
8: * @template TInput
9: * @template TOutput
10: * @template TArgument
11: *
12: * @extends PayloadPipelineInterface<TInput,TOutput,TArgument>
13: */
14: interface StreamPipelineInterface extends PayloadPipelineInterface
15: {
16: /**
17: * Pass results to a closure in batches
18: *
19: * {@see StreamPipelineInterface::collectThen()} can only be called once per
20: * pipeline, and only if {@see BasePipelineInterface::then()} is not also
21: * called.
22: *
23: * Values returned by the closure are returned to the caller via a
24: * forward-only iterator.
25: *
26: * @param (Closure(array<TInput> $results, static $pipeline, TArgument $arg): iterable<TOutput>|Closure(array<TOutput> $results, static $pipeline, TArgument $arg): iterable<TOutput>) $closure
27: * @return static
28: */
29: public function collectThen(Closure $closure);
30:
31: /**
32: * Pass results to a closure in batches if collectThen() hasn't already been
33: * called
34: *
35: * @param (Closure(array<TInput> $results, static $pipeline, TArgument $arg): iterable<TOutput>|Closure(array<TOutput> $results, static $pipeline, TArgument $arg): iterable<TOutput>) $closure
36: * @return static
37: */
38: public function collectThenIf(Closure $closure);
39:
40: /**
41: * Apply a filter to each result
42: *
43: * {@see StreamPipelineInterface::unless()} can only be called once per
44: * pipeline.
45: *
46: * If `$filter` returns `false`, `$result` is returned to the caller,
47: * otherwise it is discarded.
48: *
49: * @param Closure(TOutput|null $result, static $pipeline, TArgument $arg): bool $filter
50: * @return static
51: */
52: public function unless(Closure $filter);
53:
54: /**
55: * Apply a filter to each result if unless() hasn't already been called
56: *
57: * @param Closure(TOutput|null $result, static $pipeline, TArgument $arg): bool $filter
58: * @return static
59: */
60: public function unlessIf(Closure $filter);
61:
62: /**
63: * Run the pipeline with each of the payload's values and return the results
64: * via a forward-only iterator
65: *
66: * @return iterable<TOutput>
67: */
68: public function start(): iterable;
69:
70: /**
71: * Run the pipeline and pass each result to another pipeline
72: *
73: * @template TNextOutput
74: *
75: * @param PipelineInterface<TOutput,TNextOutput,TArgument> $next
76: * @return StreamPipelineInterface<TOutput,TNextOutput,TArgument>
77: */
78: public function startInto(PipelineInterface $next);
79: }
80: