【发布时间】:2021-02-16 07:22:53
【问题描述】:
我希望以下两个 sn-ps 都可以工作,但 F# 找不到 SelectMany 的重载
//C#
var aaa = new Dictionary<string, List<string>>();
Func<KeyValuePair<string, List<string>>, List<string>> fff = (KeyValuePair<string, List<string>> kvp) => kvp.Value;
var bbb = aaa.SelectMany(fff);
//F#
let aaa = new Dictionary<string, List<string>>()
let fff = Func<_, _>(fun (kvp:KeyValuePair<string, List<string>>) -> kvp.Value)
let bbb = aaa.SelectMany(fff) //Error FS0041 No overloads match for method 'SelectMany'
有人知道为什么吗?请注意,fff 在两个 sn-ps 中具有相同的类型
【问题讨论】:
-
可用重载: - (extension) IEnumerable.SelectMany(selector: Func>) : IEnumerable // 参数 ' selector' 不匹配 - (extension) IEnumerable.SelectMany(selector: Func>) : IEnumerable // 参数 'selector' 不匹配'不匹配
-
LINQ 在 F# 代码库中非常少见,因为有
Seq模块允许使用更惯用的代码做同样的事情。考虑使用Seq.collect -
@JL0PD 问题不是“如何做到这一点”,而是“为什么会这样”。