Skip to content

Instantly share code, notes, and snippets.

@isidore
Last active April 28, 2019 16:19
Show Gist options
  • Save isidore/e14356a2f0ecc3ede534e8c30b74000b to your computer and use it in GitHub Desktop.
Save isidore/e14356a2f0ecc3ede534e8c30b74000b to your computer and use it in GitHub Desktop.

Basic pipelines

Let's say you have the following line of code:

var _result = long.Parse(age);

snippet source

You can refactor this to pipelines with the following

var inputPipe = new InputPipe<string>("age");
var parsePipe = inputPipe.Process(long.Parse);
var collector = parsePipe.Collect();

inputPipe.Send("42");
var result = collector.SingleResult;

These will produce the same results.

But Why?!?!

Dispite the complexity add of this code, this pattern has some advantages in refactoring to async as well has advantages in monitoring. It also has advantages in testing and visualization. For example the pipeline can reder itself as the following dot file (Graphviz)

GraphViz of Pipeline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment