In converting a project to .NET Standard 2.0, FSharpFunc<T, TResult>. FromConverter method from the FSharp.Core library is not available anymore. Is there a way to convert this code to a .NET Standard 2.0 FSharp.Core implementation?
async Task<Unit> RunProcess(FSharpMailboxProcessor<T> mailbox, Func<T, Task> process) { ... }
public BaseMailboxProcessor(Func<TFuncInput, Task> process, Action<Exception, TFuncInput> errorHandler = null, CancellationToken? cancellationToken = null)
{
m_ErrorHandler = errorHandler;
m_TokenSource = cancellationToken.HasValue ? CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Value) :
new CancellationTokenSource();
var cancellationOption = FSharpOption<CancellationToken>.Some(m_TokenSource.Token);
Converter<FSharpMailboxProcessor<TMailboxInput>, FSharpAsync<Unit>> converter = (mailbox) =>
{
return FSharpAsync.AwaitTask<Unit>(RunProcess(mailbox, process));
};
m_Mailbox = new FSharpMailboxProcessor<TMailboxInput>(FSharpFunc<FSharpMailboxProcessor<TMailboxInput>, FSharpAsync<Unit>>.FromConverter(converter), cancellationOption);
m_Mailbox.Start();
}
You should be able to use FuncConvert.ToFSharpFunc, this appears to still be present in the netstandard version of FSharp.Core.
You can trivially define your own:
let ToFSharpFunc (converter: System.Func<_, _>) = fun t -> converter.Invoke t
Also, if you need to use an FSharpFunc in C# you can simply call .Invoke on it where .Invoke on the FSharpFunc object is a Func.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With