<p>In JavaScript, using the Prototype library, the following functional construction is possible:</p>

<pre><code>var words = ["aqueous", "strength", "hated", "sesquicentennial", "area"];
words.pluck('length');
//-&gt; [7, 8, 5, 16, 4]
</code></pre>

<p>Note that this example code is equivalent to</p>

<pre><code>words.map( function(word) { return word.length; } );
</code></pre>

<p>I wondered if something similar is possible in F#:</p>

<pre><code>let words = ["aqueous"; "strength"; "hated";"sesquicentennial"; "area"]
//val words: string list
List.pluck 'Length' words
//int list = [7; 8; 5; 16; 4]
</code></pre>

<p>without having to write:</p>

<pre><code>List.map (fun (s:string) -&gt; s.Length) words
</code></pre>

<p>This would seem quite useful to me because then you don't have to write functions for every property to access them.</p>

[{'answer_id': 79511, 'author': 'Gavin', 'author_id': 2377, 'author_profile': 'https://Stackoverflow.com/users/2377', 'pm_score': 1, 'selected': False, 'text': '<p>Prototype\'s <code>pluck</code> takes advantage of that in Javascript <code>object.method()</code> is the same as <code>object[method]</code>. </p>\n\n<p>Unfortunately you can\'t call <code>String.Length</code> either because it\'s not a static method. You can however use:</p>\n\n<pre><code>#r "FSharp.PowerPack.dll" \nopen Microsoft.FSharp.Compatibility\nwords |&gt; List.map String.length \n</code></pre>\n\n<p><a href="http://research.microsoft.com/fsharp/manual/FSharp.PowerPack/Microsoft.FSharp.Compatibility.String.html" rel="nofollow noreferrer">http://research.microsoft.com/fsharp/manual/FSharp.PowerPack/Microsoft.FSharp.Compatibility.String.html</a></p>\n\n<p>However, using <code>Compatibility</code> will probably make things more confusing to people looking at your code.</p>\n'}, {'answer_id': 86084, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': '<p>I saw your request on the F# mailing list. Hope I can help. </p>\n\n<p>You could use type extension and reflection to allow this. We simple extend the generic list type with the pluck function. Then we can use pluck() on any list. An unknown property will return a list with the error string as its only contents.</p>\n\n<pre><code>type Microsoft.FSharp.Collections.List&lt;\'a&gt; with\n    member list.pluck property = \n        try \n            let prop = typeof&lt;\'a&gt;.GetProperty property \n            [for elm in list -&gt; prop.GetValue(elm, [| |])]\n        with e-&gt; \n            [box &lt;| "Error: Property \'" + property + "\'" + \n                            " not found on type \'" + typeof&lt;\'a&gt;.Name + "\'"]\n\nlet a = ["aqueous"; "strength"; "hated"; "sesquicentennial"; "area"]\n\na.pluck "Length" \na.pluck "Unknown"\n</code></pre>\n\n<p>which produces the follow result in the interactive window:</p>\n\n<pre>\n> a.pluck "Length" ;; \nval it : obj list = [7; 8; 5; 16; 4]\n\n> a.pluck "Unknown";;\nval it : obj list = ["Error: Property \'Unknown\' not found on type \'String\'"]\n</pre>\n\n<p>warm regards,</p>\n\n<p>DannyAsher</p>\n\n<p>>\n>\n>\n>\n></p>\n\n<p>NOTE: When using <code>&lt;pre</code>> the angle brackets around <pre>&lt;\'a></pre> didn\'t show though in the preview window it looked fine. The backtick didn\'t work for me. Had to resort you the colorized version which is all wrong. I don\'t think I\'ll post here again until FSharp syntax is fully supported. </p>\n'}]
['https://Stackoverflow.com/questions/76571', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6264/']