简体   繁体   English

Scala将元素追加到索引序列

[英]Scala append elements to Indexed Sequence

I have a indexed sequence of 10 doubles and I want to append few more doubles to the original indexed sequence. 我有一个10倍的索引序列,我想在原始索引序列上再添加几个双精度数。 I tried using :: and ++ but it doesn't work. 我尝试使用::和++,但无法正常工作。 I can only use val. 我只能使用val。

val features = functionCount.map(_.toDouble).toIndexedSeq //original indexed sequence
features +=  avgLength //tried :: also

How do I append more doubles to this sequence, I need a IndexedSeq in the end. 如何在此序列上附加更多的双精度数,最后我需要一个IndexedSeq。

You can't change features , unless it's mutable. 除非它是可变的,否则您不能更改features Given the comment that "you can only use val", this sounds like homework, and, if it is, I doubt you can use mutable sequences either. 考虑到“您只能使用val”的注释,这听起来像是作业,如果可以的话,我怀疑您是否也可以使用可变序列。 In that case, you have to abandon that approach and tackle the problem at a much higher level, with either recursion or folding. 在这种情况下,您必须放弃该方法,并通过递归或折叠在更高层次上解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM