gpt4 book ai didi

list - 如何串联F#中的列表(和其他集合)?

转载 作者:行者123 更新时间:2023-12-03 14:52:14 26 4
gpt4 key购买 nike

F#是否提供惯用的级联方式

  • 序列和列表一起吗?
  • 列出并一起列出一个列表? (非破坏性)
  • 列出并一起列出是否具有破坏性的列表?
  • 可变数组一起破坏性地组合成另一个可变数组?

  • 而且您也可以连接元组吗?

    最佳答案

    sequence and list together



    对此没有特殊功能。如果序列是第一个,列表是第二个,那么您必须在将第一个列表转换为列表(然后在使用 List.append追加时复制它)之间进行选择,或者先使用 Seq.append,再使用 List.ofSeq复制两个列表。

    因此编写自己的函数将很有意义。

    list and list together into a list? (non-destructive)


    List.append可以做到这一点。

    list and list together into a list if it is destructive



    列表是不可变的,因此没有破坏性附加。

    mutable arrays together, destructively, into another mutable array?



    在.NET中,您无法调整数组大小,因此没有破坏性的方法。 Array.append创建一个新数组(并且比其他选项要快,因为它事先知道结果的大小)。

    And can you concatenate tuples too?



    不可以。类型系统不允许您表达要追加元组的函数的类型(它们必须具有静态已知的大小)。

    关于list - 如何串联F#中的列表(和其他集合)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28567483/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com