Last active
February 3, 2018 18:24
-
-
Save pavel-agarkov/89b7599a577f7197b6ff68894bbd0a55 to your computer and use it in GitHub Desktop.
Revisions
-
pavel-agarkov revised this gist
Feb 3, 2018 . 1 changed file with 30 additions and 30 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,36 @@ using System.Collections.Generic; using System.Linq; public static class Test { static Test() { 1d.Pipe(TimeSpan.FromDays, AddHours(3), ToString, ToLower); Enumerable.Range(0, 100).Pipe( Select(n => n * 2), Where(n => n % 2 > 0), Enumerable.Sum, Convert.ToString ); } public static Func<TimeSpan, TimeSpan> AddHours(int hours) => (TimeSpan timeSpan) => timeSpan.Add(TimeSpan.FromHours(hours)); public static string ToString(this TimeSpan timeSpan) => timeSpan.ToString(); public static string ToLower(this string str) => str.ToLower(); public static Func<IEnumerable<int>, IEnumerable<int>> Select(Func<int, int> selector) => (IEnumerable<int> list) => list.Select(selector); public static Func<IEnumerable<int>, IEnumerable<int>> Where(Func<int, bool> filter) => (IEnumerable<int> list) => list.Where(filter); } public static class PipeExtensions { public static TResult Pipe<TInput, TResult> @@ -39,33 +69,3 @@ public static TResult4 Pipe<TInput, TResult, TResult1, TResult2, TResult3, TResu Func<TResult3, TResult4> func4) => func4(func3(func2(func1(func(input))))); } -
pavel-agarkov created this gist
Feb 3, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ using System; using System.Collections.Generic; using System.Linq; public static class PipeExtensions { public static TResult Pipe<TInput, TResult> (this TInput input, Func<TInput, TResult> func) => func(input); public static TResult1 Pipe<TInput, TResult, TResult1> (this TInput input, Func<TInput, TResult> func, Func<TResult, TResult1> func1) => func1(func(input)); public static TResult2 Pipe<TInput, TResult, TResult1, TResult2> (this TInput input, Func<TInput, TResult> func, Func<TResult, TResult1> func1, Func<TResult1, TResult2> func2) => func2(func1(func(input))); public static TResult3 Pipe<TInput, TResult, TResult1, TResult2, TResult3> (this TInput input, Func<TInput, TResult> func, Func<TResult, TResult1> func1, Func<TResult1, TResult2> func2, Func<TResult2, TResult3> func3) => func3(func2(func1(func(input)))); public static TResult4 Pipe<TInput, TResult, TResult1, TResult2, TResult3, TResult4> (this TInput input, Func<TInput, TResult> func, Func<TResult, TResult1> func1, Func<TResult1, TResult2> func2, Func<TResult2, TResult3> func3, Func<TResult3, TResult4> func4) => func4(func3(func2(func1(func(input))))); } public static class Test { public static Func<TimeSpan, TimeSpan> AddHours(int hours) => (TimeSpan timeSpan) => timeSpan.Add(TimeSpan.FromHours(hours)); public static string ToString(this TimeSpan timeSpan) => timeSpan.ToString(); public static string ToLower(this string str) => str.ToLower(); public static Func<IEnumerable<int>, IEnumerable<int>> Select(Func<int, int> selector) => (IEnumerable<int> list) => list.Select(selector); public static Func<IEnumerable<int>, IEnumerable<int>> Where(Func<int, bool> filter) => (IEnumerable<int> list) => list.Where(filter); static Test() { 1d.Pipe(TimeSpan.FromDays, AddHours(3), ToString, ToLower); Enumerable.Range(0, 100).Pipe( Select(n => n * 2), Where(n => n % 2 > 0), Enumerable.Sum, Convert.ToString ); } }