Skip to content
Permalink
Browse files

Make interface generic

  • Loading branch information...
ploeh committed Jan 10, 2018
1 parent e3ee5d6 commit 2cba6d7625b08054caf6f42cc30898ced704848f
@@ -17,19 +17,9 @@ public ChurchAnd(IChurchBoolean x, IChurchBoolean y)
this.y = y;
}

public object Match(object trueCase, object falseCase)
public T Match<T>(T trueCase, T falseCase)
{
return x.Match(y.Match(trueCase, falseCase), falseCase);
}

public int Match(int trueCase, int falseCase)
{
return this.x.Match(y.Match(trueCase, falseCase), falseCase);
}

public string Match(string trueCase, string falseCase)
{
return this.x.Match(y.Match(trueCase, falseCase), falseCase);
}
}
}
@@ -10,7 +10,7 @@ public static class ChurchBoolean
{
public static bool ToBool(this IChurchBoolean b)
{
return (bool)b.Match(true, false);
return b.Match(true, false);
}

public static IChurchBoolean ToChurchBoolean(this bool b)
@@ -8,17 +8,7 @@ namespace Ploeh.Samples.ChurchEncoding
{
public class ChurchFalse : IChurchBoolean
{
public object Match(object trueCase, object falseCase)
{
return falseCase;
}

public int Match(int trueCase, int falseCase)
{
return falseCase;
}

public string Match(string trueCase, string falseCase)
public T Match<T>(T trueCase, T falseCase)
{
return falseCase;
}
@@ -17,19 +17,9 @@ public ChurchNot(IChurchBoolean b)
this.b = b;
}

public object Match(object trueCase, object falseCase)
public T Match<T>(T trueCase, T falseCase)
{
return b.Match(falseCase, trueCase);
}

public int Match(int trueCase, int falseCase)
{
return this.b.Match(falseCase, trueCase);
}

public string Match(string trueCase, string falseCase)
{
return this.b.Match(falseCase, trueCase);
}
}
}
@@ -17,19 +17,9 @@ public ChurchOr(IChurchBoolean x, IChurchBoolean y)
this.y = y;
}

public object Match(object trueCase, object falseCase)
public T Match<T>(T trueCase, T falseCase)
{
return x.Match(trueCase, y.Match(trueCase, falseCase));
}

public int Match(int trueCase, int falseCase)
{
return this.x.Match(trueCase, y.Match(trueCase, falseCase));
}

public string Match(string trueCase, string falseCase)
{
return this.x.Match(trueCase, y.Match(trueCase, falseCase));
}
}
}
@@ -8,17 +8,7 @@ namespace Ploeh.Samples.ChurchEncoding
{
public class ChurchTrue : IChurchBoolean
{
public object Match(object trueCase, object falseCase)
{
return trueCase;
}

public int Match(int trueCase, int falseCase)
{
return trueCase;
}

public string Match(string trueCase, string falseCase)
public T Match<T>(T trueCase, T falseCase)
{
return trueCase;
}
@@ -8,10 +8,6 @@ namespace Ploeh.Samples.ChurchEncoding
{
public interface IChurchBoolean
{
object Match(object trueCase, object falseCase);

int Match(int trueCase, int falseCase);

string Match(string trueCase, string falseCase);
T Match<T>(T trueCase, T falseCase);
}
}

0 comments on commit 2cba6d7

Please sign in to comment.
You can’t perform that action at this time.