A function of mine produces an array - an ordered, contiguously numbered set of records. But as far as I know Scala Array is a mutable collection, while functional approach suggests it would make more sense to return an immutable collection in a general case. So I just call Array.toIndexedSeq
to return an IndexedSeq
instead of 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?
Can this be considered a correct thing to do?
Yes.
Doesn't it introduce any inobvious behaviour which can influence the function and the result usage and be probably considered undesirable?
No, not that I know of.
Are there any better practices for the issue?
If possible, try to eliminate the use of array altogether, unless of course the performance is paramount.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With