Skip to content

Instantly share code, notes, and snippets.

@vgerbase
Created July 8, 2018 18:19
Show Gist options
  • Save vgerbase/1e2951ba5a424929a07b6332436bba80 to your computer and use it in GitHub Desktop.
Save vgerbase/1e2951ba5a424929a07b6332436bba80 to your computer and use it in GitHub Desktop.
Pipe extension in C#
public static class PipeExtensions
{
public static TOut Then< TIn, TOut >(this TIn item, Func< TIn, TOut > fn)
{
return fn(item);
}
}
public class PipeTest
{
[Fact]
public void ShouldPipeItemToFunction()
{
"-2"
.Then(int.Parse)
.Then(Math.Abs)
.Then(i => i + 2)
.Should().Be(4);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment