OneOf - made static Match() method

This commit is contained in:
John Colvin committed 2019-04-12 13:45:25 -05:00
1 parent 015be785e1
commit 33f399893e
1 file changed
+10
+10
View File
@@ -22,6 +22,16 @@ namespace bts {
} else return new OneOf<A, B, C>();
}
public static void Match<A, B, C>(Func<A> a, Func<B> b, Func<C> c, Action<A> on_a, Action<B> on_b, Action<C> on_c) {
if (a() is A as_a) {
on_a(as_a);
} else if (b() is B as_b) {
on_b(as_b);
} else if (c() is C as_c) {
on_c(as_c);
}
}
public static T infer<T, A, B>(object value, Func<A, T> a, Func<B, T> b) =>
OneOf<A, B>.infer(value).Match(a, b);
}