public class DefaultEither : Either {
private A theA;
private B theB;
public void SetB (B b) {
this.theB = b;
}
public void SetA (A a) {
this.theA = a;
}
public delegate B Func (B b);
public DefaultEither(A _theA, B _theB){
theA = _theA;
theB = _theB;
}
public static DefaultEither newA(A _theA)
{
return new DefaultEither(_theA,default(B));
}
public static DefaultEither newB(B _theB)
{
return new DefaultEither(default(A),_theB);
}
public A a()
{
return theA;
}
public bool isA()
{
return theA != null;
}
public B b()
{
return theB;
}
public bool isB()
{
return theB != null;
}
public Either fmap(System.Func f, Either e) {
if (e.isA ()) {
return e;
}
this.SetB (f (e.b()));
return this;
}
}