This file contains 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
public class Claim | |
{ | |
public Workflow Workflow { get; } | |
} | |
public abstract class Workflow | |
{ | |
public abstract void Fire(Transition transition, Claim claim); | |
} | |
public class FullWF : Workflow |
This file contains 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
class VisitorImpl : PolynomialBaseVisitor<INode> | |
{ | |
public override INode VisitPlusminus([NotNull] PolynomialParser.PlusminusContext context) | |
{ | |
var left = context.expr()[0]; | |
var right = context.expr()[1]; | |
if (context.MINUS() != null) | |
return new SubtractNode(Visit(left), Visit(right)); |
This file contains 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
public interface INode | |
{ | |
double Eval(Dictionary<char, double> variablesValue); | |
} | |
public class AddNode : INode | |
{ | |
private readonly INode _left; | |
private readonly INode _right; |
This file contains 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
public static Func<T, T> ToFunc<T>(Action<T> a) | |
{ | |
return t => | |
{ | |
a(t); | |
return t; | |
}; | |
} |
This file contains 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
public static Func<T, Result<S, TError>> ToSwitchFunction<T, S, TError>(Func<T, S> a) | |
{ | |
return t => | |
{ | |
return a(t); | |
}; | |
} | |
public static Func<T, Result<T, TError>> ToSwitchFunction<T, TError>(Action<T> a) | |
{ |
This file contains 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
public static Result<S, TError> Then<S, TValue, TError>(this Result<TValue, TError> r, Func<TValue, Result<S, TError>> f) | |
=> Bind(f)(r); |
This file contains 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
public static Func<Result<TSuccess, TError>, Result<TSuccess, TError>> Bind<TSuccess, TError>(Func<TSuccess, Result<TSuccess, TError>> f) | |
{ | |
return r => r.Match(t => f(t), e => new Result<TSuccess, TError>(e)); | |
} |
This file contains 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
Union<Customer,Failure> ValidateEmail(Customer c) { | |
if(c.Email is null) | |
return new Failure("Email is not valid"); | |
return c; | |
} | |
Union<Customer,Failure> ValidateNameSurname(Customer c) { | |
if(c.Name is null) | |
return new Failure("Name is not valid"); |
This file contains 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
Union<Success,Failure> ValidateEmail(Customer c) { ... } | |
public class Success {} | |
public class Failure { | |
public string Message {get;} | |
public Failure(string message) { | |
Message = message; | |
} |
This file contains 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
Result ValidateEmail(Customer c) { ... } | |
Result ValidateNameSurname(Customer c) { ... } | |
Result SendEmail(Customer c) { ... } | |
Result SendEmailToCustomerIfValid(Customer c) { | |
var validateSurname = ValidateNameSurname(c); | |
if(!validateSurname.Success) | |
return validateSurname; | |
var validateEmail = ValidateEmail(c); |
NewerOlder