【发布时间】:2010-09-09 17:55:20
【问题描述】:
在 JavaScript 中,使用 Prototype 库,可以进行以下函数构造:
var words = ["aqueous", "strength", "hated", "sesquicentennial", "area"];
words.pluck('length');
//-> [7, 8, 5, 16, 4]
请注意,此示例代码等效于
words.map( function(word) { return word.length; } );
我想知道在 F# 中是否有类似的可能:
let words = ["aqueous"; "strength"; "hated";"sesquicentennial"; "area"]
//val words: string list
List.pluck 'Length' words
//int list = [7; 8; 5; 16; 4]
不用写:
List.map (fun (s:string) -> s.Length) words
这对我来说似乎很有用,因为这样您就不必为每个属性编写函数来访问它们。
【问题讨论】:
标签: javascript f# functional-programming prototypejs