Converting Unit to void baked into the compiler. There's a FuncConvert class in F # Core to convert between FSharpFunc and Converter . What about defining a similar class to convert Action<T> to Func<T, Unit> ?
static class ActionConvert { private static readonly Unit Unit = MakeUnit(); public static Func<T, Unit> ToFunc<T>(Action<T> action) { return new Func<T, Unit>(x => { action(x); return Unit; }); } private static Unit MakeUnit() {
Then you could do
var foo = new Foo<int>(); var func = ActionConvert.ToFunc<int>(foo.DoStuff);
Perhaps you can even discard the Unit instance and return null .
Daniel
source share