# Creating Pipelines

# Facade

The default way to start with Pipelines is using the package's facade. All operators can also be accessed via the Facade.

use MOIREI\Pipeline\Facades\Pipeline;

...

$value = Pipeline::with([2, 3])->pipe([
  Pipeline::map(
    fn ($v) => $v * 2,
  ),
  Pipeline::collect(),
  fn (Collection $v) => $v->sum()
]);

# Using global functions

If you're not a fan of Facades, the above can be re-written using the available global function pipeline and class pipe.

$value = pipeline([2, 3])->pipe([
  \pipe::map(
    fn ($v) => $v * 2,
  ),
  \pipe::collect(),
  fn (Collection $v) => $v->sum()
]);

# pipeline

pipeline(
  $payload,
  $pipes,
  $context,
  $method, // the via method
);

If pipes is not null, the pipeline is immidiatedly processed and the resulting value is returned

$value = pipeline(2, [
  \pipe::map(fn ($v) => $v * 2)
]);

Otherwise the pipeline instance is returned

$pipeline = pipeline(2);

$value = $pipeline->pipe([
  \pipe::map(fn ($v) => $v * 2)
])

# pipe

This is a global class that exposes the operators as static methods for easy namespaced access.

We don't want something like \pipe::collect overriding Laravel's collect function.