/** * Creates a `Stream` containing the provided data. * ```php * s('! World Hello') * ->then(split(' ')) * ->then('array_reverse') * ->then(join(' ')) * ->get(); // 'Hello World !' * ``` * * @signature a -> Stream(a) * @param mixed $data * @return Stream */ function s($data) { return Stream::of($data); }
/** * Adds an operation to a stream. * * @param string $operation * @param mixed $args * @param Stream $stream * @return Stream */ protected static function apply($operation, $args, $stream) { if ($stream->type == 'Error') { return Stream::of(Error::of("Could not apply {$operation} to {$stream->type}", $stream->data)); } if (!Stream::canApply($operation, $stream->type)) { $data = toString($stream->data); return Stream::of(Error::of("Could not apply {$operation} to {$stream->type}({$data})")); } return Stream::with($stream->data, Stream::optimize(append(['name' => $operation, 'args' => $args], $stream->operations)), Stream::returnOf($operation, $stream->type)); }