Created
May 15, 2016 04:12
-
-
Save johnazariah/f6f4761f4e542ff8f584560c50e96b31 to your computer and use it in GitHub Desktop.
F# vs C#
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 characters
using System; | |
namespace FSM.BankAccount | |
{ | |
public abstract class BankAccountState | |
{ | |
public static readonly BankAccountState ZeroBalanceState = new ChoiceTypes.ZeroBalanceState(); | |
public static readonly BankAccountState ActiveState = new ChoiceTypes.ActiveState(); | |
public static readonly BankAccountState OverdrawnState = new ChoiceTypes.OverdrawnState(); | |
public static readonly BankAccountState ClosedState = new ChoiceTypes.ClosedState(); | |
public abstract T Match<T>( | |
Func<T> zeroBalanceStateFunc, | |
Func<T> activeStateFunc, | |
Func<T> overdrawnStateFunc, | |
Func<T> closedStateFunc); | |
private static class ChoiceTypes | |
{ | |
// ReSharper disable MemberHidesStaticFromOuterClass | |
public class ZeroBalanceState : BankAccountState | |
{ | |
public override T Match<T>( | |
Func<T> zeroBalanceStateFunc, | |
Func<T> activeStateFunc, | |
Func<T> overdrawnStateFunc, | |
Func<T> closedStateFunc) | |
{ | |
return zeroBalanceStateFunc(); | |
} | |
} | |
public class ActiveState : BankAccountState | |
{ | |
public override T Match<T>( | |
Func<T> zeroBalanceStateFunc, | |
Func<T> activeStateFunc, | |
Func<T> overdrawnStateFunc, | |
Func<T> closedStateFunc) | |
{ | |
return activeStateFunc(); | |
} | |
} | |
public class OverdrawnState : BankAccountState | |
{ | |
public override T Match<T>( | |
Func<T> zeroBalanceStateFunc, | |
Func<T> activeStateFunc, | |
Func<T> overdrawnStateFunc, | |
Func<T> closedStateFunc) | |
{ | |
return overdrawnStateFunc(); | |
} | |
} | |
public class ClosedState : BankAccountState | |
{ | |
public override T Match<T>( | |
Func<T> zeroBalanceStateFunc, | |
Func<T> activeStateFunc, | |
Func<T> overdrawnStateFunc, | |
Func<T> closedStateFunc) | |
{ | |
return closedStateFunc(); | |
} | |
} | |
// ReSharper restore MemberHidesStaticFromOuterClass | |
} | |
} | |
} |
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 characters
type BankAccountState = | |
| ZeroBalanceState | |
| ActiveState | |
| OverdrawnState | |
| ClosedState |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment