元组将按照什么顺序排序? [英] What order will tuples sort in?
本文介绍了元组将按照什么顺序排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
元组将以什么顺序排序?我知道F#中的元组实现了IStructuralComparable,但是我找不到关于它的任何文档.
What order will tuples sort in? I understand that tuples in F# implements IStructuralComparable but I can't find any documentation on what that is.
例如,如果我向Seq.SortBy输入一个返回元组的函数,那么我的序列将按什么顺序?
For example, If I input a function to Seq.SortBy that returns a tuple, what order would my sequence be in?
推荐答案
让我们做实验.在互动提示中输入
Let's do the experiment. Type this into the interactive prompt
let l = [ (4,2) ; (1,2) ; (2,3) ; (2,1) ]
l |> Seq.sortBy id;;
并获得
val it : seq<int * int> = seq [(1, 2); (2, 1); (2, 3); (4, 2)]
这是明显的排序类型-按第一个元素排序,然后在第二个元素内排序,依此类推.
which is the obvious type of ordering -- sort by first element, then within that sort by second, etc.
这篇关于元组将按照什么顺序排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文