Created
July 8, 2018 18:19
-
-
Save vgerbase/1e2951ba5a424929a07b6332436bba80 to your computer and use it in GitHub Desktop.
Pipe extension in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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