Trying to figure out how to create a method that takes in a list of methods and another parameter. I have my method that I created in C# that I’m trying to carry over to F#:
public interface IValidator
{
MethodResult Validate(IList<Func<userModel, MethodResult>> validationMethods
, userModeltoValidate);
}
I’ve tried something like:
type public IValidator =
abstract Validate : IList<(BasicUserModel -> MethodResult<'a>)>, BasicUserModel
-> MethodResult<'a>
But it doesn’t like the syntax even if I surround the parameter signature with parentheses. The end goal is to have a method that takes in a list of methods and run them by iterating through the list.
public MethodResult Validate(IList<Func<BasicUserModel, MethodResult>> validationMethods,
BasicUserModel toValidate)
{
...
}
The looping part I can get easily with F#, it’s the method signature syntax for both the abstract type and the type that’s implementing the method that’s killing me.
In the abstract method declaration, rather than separating the argument types with commas they should be separated by asterisks, as if the method took a tuple:
Here are a few other thoughts:
publickeyword on your type declaration.seq<_>than anIList<_>, unless you’re likely to need random access rather than looping.MethodResult<'a>using an undeclared type parameter'a). If you want a non-generic method on a generic type, then add the'aparameter to the type declaration:type IValidator<'a> = ....