# IPipeline

A pipeline represents a pre-built set of functions that are chained together. Its usage is very simple, either the pipeline has everything it needs to run i.e IPipeline or requires some initial input IPipeline\<TInput>.

```csharp
public interface IPipeline
{
    void Run(IProgressTracker progress = null);
}

public interface IPipeline<TInput>
{
    void Run(TInput input, IProgressTracker progress = null);
}
```

An IPipeline is created from using a PipelineBuilder

## IReversePipelineBuilder

An IReversePipelineBuilder is used to build up a pipeline starting from the desired output, working backwards specifying the required input. It is useful for when you know what you want, but are still working out how to get there. There are useful extension methods that can help with working out how to get to the desired output:

* [Faze.Gallery.Extensions.PipelineExtensions](https://github.com/b-faze/faze/blob/d67c933395713416cb0109a63fa417cc832f10ba/src/examples/gallery/Faze.Examples.Gallery/Extensions/ReversePipelineExtensions.cs)
* [Faze.Core.Pipelines.PipelineExtensions](https://github.com/b-faze/faze/blob/d67c933395713416cb0109a63fa417cc832f10ba/src/libraries/Faze.Core/Faze.Core/Extensions/ReversePipelineExtensions.cs)

```csharp
public interface IReversePipelineBuilder
{
    IReversePipelineBuilder<TNext> Require<TNext>(Action<TNext> fn);
}

public interface IReversePipelineBuilder<T>
{
    IReversePipelineBuilder<TNext> Require<TNext>(Func<TNext, T> fn);
    IReversePipelineBuilder<TNext> Require<TNext>(Func<TNext, IProgressTracker, T> fn);
    IPipeline<T> Build();
    IPipeline Build(Func<T> fn);
}
```

### Example Usage

See [OXGoldImagePipeline.cs](https://github.com/b-faze/faze/blob/207ab4de2be5bd3a1317280c5c7826ac0aec2d29/src/examples/gallery/Faze.Examples.Gallery/Visualisations/OX/OXGoldImagePipeline.cs) for the example below.

```csharp
IPipeline pipeline = ReversePipelineBuilder.Create()
    .GallerySave(galleryService, galleryMetaData)
    .Render(new SquareTreeRenderer(rendererConfig))
    .Paint(new GoldInterpolator())
    .MapValue(fn)
    .LoadTree(OXDataGenerator5.Id, treeDataProvider);
```

`ReversePipelineBuilder.Create()` initialises an empty `IReversePipelineBuilder` object.

`.GallerySave(...)` create the first requirement and returns an `IReversePipelineBuilder<IPaintedTreeRenderer>`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://b-hub.gitbook.io/faze/v2.0.0/overview/ipipeline.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
