// Your Match method returns void, it is not good in functional programming, // because, whole purpose of the method returning void is the change state, // and in FP state is immutable // That's why I've created PureMatch method for you public Choice <T1Out, T2Out> PureMatch <T1Out, T2Out>(Func <T1, T1Out> onChoice1Of2, Func <T2, T2Out> onChoice2Of2) { Choice <T1Out, T2Out> result = null; Match( t1 => result = new Choice1Of2 <T1Out, T2Out>(onChoice1Of2(t1)), t2 => result = new Choice2Of2 <T1Out, T2Out>(onChoice2Of2(t2))); return(result); }
// This method will help with the complex matching public static Choice <T1, T2> Flat <T1, T2>(this Choice <Choice <T1, T2>, T2> choice) { Choice <T1, T2> result = null; choice.Match( t1 => result = t1, t2 => result = new Choice2Of2 <T1, T2>(t2)); return(result); }