通过元组成员映射元组列表 [英] Mapping a list of tuples by tuple members

查看:57
本文介绍了通过元组成员映射元组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个decimal*decimal

let tup = [(1M, 2M); (2M, 3M); (3M, 3M); (4M, 5M); (5M, 6M); (7M, 6M); (8M, 9M); (10M, 9M)]

我需要一个可以将所有值组合在一起的函数,例如

I need a function that can group all of the values together if they can be connected, e.g.,

map[(100, [1M; 2M; 3M]); (101, [4M; 5M; 6M; 7M]); (102, [8M; 9M; 10M])]

我不能只做一个List.groupBy,因为它错过了可能会被另一个十进制"连接的其他任何东西.映射中的int值是任意的.我希望能够播种"初始值,然后将每个值递增一些.

I can't just do a List.groupBy because that misses anything else that may be connected "down the line" by another decimal value. The int values in the map are arbitrary. I'd like to be able to "seed" the starting value then increase each incrementally by some value.

可以实现此功能的函数是什么样的?

What's the function look like that can do this?

推荐答案

我正确的意思是连接"是指数字表示无向图中的节点,元组表示无向图中的边吗?据我所知,标准库中没有函数可以做到这一点.您可以搜索一些执行基本图形操作的库.您要执行的操作是划分为已连接的组件.

Am I right that by 'connected' you mean that numbers represent nodes and tuples represent edges in undirected graph? As far as I know there is no function in standard library which would do that. You can search for some library that perform basic graph operations. The operation you want to perform is division to connected components.

您也可以尝试从头开始实现该功能. 这是一些不错的尝试.

You can also try to implement that function from the scratch. Here is some nice attempt.

这篇关于通过元组成员映射元组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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