In C#, if I had a widget definition, say:
class widget
{
public string PrettyName() { ... do stuff here }
}
and I wanted to allow for easy printing of a list of Widgets, I might do this:
namespace ExtensionMethods
{
public static PrintAll( this IEnumerable<Widget> widgets, TextWriter writer )
{
foreach(var w in widgets) { writer.WriteLine( w.PrettyName() ) }
}
}
How would I accomplish something similar with a record type and a collection (List or Seq preferrably in F#). I'd love to have a list of Widgest and be able to call a function right on the collection that did something like this. Assume (since it's F#) that the function would not be changing the state of the collection that it's attached to, but returning some new value.