Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Xunit;
- namespace Category
- {
- public static class CategoryExtensions
- {
- public static Func<A, C> Compose<A, B, C>(this Func<B, C> g, Func<A, B> f)
- {
- return x => g(f(x));
- }
- }
- public class CategoryTest
- {
- Func<int, bool> f = (int i) => i % 2 == 0;
- Func<bool, string> g = (bool b) => b ? "True" : "False";
- [Theory]
- [InlineData(2, "True")]
- [InlineData(3, "False")]
- public void Composition(int input, string output)
- {
- Func<int, string> composed = g.Compose(f);
- Assert.Equal(composed(input), output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement