gpt4 book ai didi

arrays - 如果 Scala 中需要不可变数组,返回 IndexesSeq 而不是 Array 是否正确?

转载 作者:行者123 更新时间:2023-12-04 23:28:07 24 4
gpt4 key购买 nike

我的一个函数产生一个数组——一个有序的、连续编号的记录集。但据我所知,Scala 数组是一个可变集合,而函数式方法表明在一般情况下返回一个不可变集合更有意义。所以我只是打电话Array.toIndexedSeq返回 IndexedSeq而不是 Array .这可以被认为是正确的做法吗?它是否会引入任何可能影响功能和结果使用并可能被认为不受欢迎的不明显行为?这个问题有没有更好的做法?

最佳答案

Can this be considered a correct thing to do?



是的。

Doesn't it introduce any inobvious behaviour which can influence the function and the result usage and be probably considered undesirable?



不,不是我所知道的。

Are there any better practices for the issue?



如果可能,尽量完全避免使用数组,除非性能是最重要的。

关于arrays - 如果 Scala 中需要不可变数组,返回 IndexesSeq 而不是 Array 是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9167042/

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