F#等效于ILookup< string,string> [英] F# equivalent of ILookup<string, string>

查看:137
本文介绍了F#等效于ILookup< string,string>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是F#新手,我正在尝试用F#编写一个小程序,该程序与我拥有的C#库进行对话. C#函数采用类型为ILookup< string,string>的参数.

I'm a F# newbie and I'm trying to write a small program in F# that talks to a C# library that I have. The C# function takes a parameter that is of type ILookup<string,string>.

我如何从F#中调用它?

How do I call this from F# ?

致谢

Alan

推荐答案

您可以使用在C#中完全相同的方法来执行此操作,并使用System.Linq.Enumerable.ToLookup ()方法为您生成ILookup.

You could do this the exact same way it's done in C# and use the System.Linq.Enumerable.ToLookup() method to generate an ILookup for you.

通过向Seq模块添加扩展,也可以使元组序列转换为ILookup,从而使这种感觉更像是惯用的F#.函数将元组序列转换为IDictionary:

You could also make this feel more like idiomatic F# by adding an extension to the Seq module that turns a sequence of tuples into an ILookup the same way the "dict" function turns a sequence of tuples into an IDictionary:

module Seq =

    let inline toLookup items = 
        System.Linq.Enumerable.ToLookup(items, fst, snd)



这篇关于F#等效于ILookup&lt; string,string&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆