In C #, I can define an extension method for a generic array of type T as follows:
public static T GetOrDefault<T>(this T[] arr, int n) { if (arr.Length > n) { return arr[n]; } return default(T); }
but for life I canβt understand how to do the same in F #! I tried type 'a array with , type array<'a> with and type 'a[] with , and the compiler was not happy with any of them.
Can someone tell me the right to do this in F #?
Of course, I can do this by eclipsing the Array module and adding a function for this is easy enough, but I really want to know how to do this as an extension method!
arrays c # extension-methods f #
theburningmonk Aug 06 2018-12-21T00: 00Z
source share