Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System;
  2. using Xunit;
  3.  
  4. namespace Category
  5. {
  6. public static class CategoryExtensions
  7. {
  8. public static Func<A, C> Compose<A, B, C>(this Func<B, C> g, Func<A, B> f)
  9. {
  10. return x => g(f(x));
  11. }
  12. }
  13. public class CategoryTest
  14. {
  15. Func<int, bool> f = (int i) => i % 2 == 0;
  16.  
  17. Func<bool, string> g = (bool b) => b ? "True" : "False";
  18.  
  19. [Theory]
  20. [InlineData(2, "True")]
  21. [InlineData(3, "False")]
  22. public void Composition(int input, string output)
  23. {
  24. Func<int, string> composed = g.Compose(f);
  25.  
  26. Assert.Equal(composed(input), output);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement