score:2
The blunt reason is usually performance. With the reasoning that local (!) var
s do not break FP and still allow concurrency to work.
In this case, the reason probably is another. The implementation works also for non-Lists, only using the IterableOnce
methods.
score:4
The designers of the standard library chose performance over purity.
The main downside is that the standard library is not a good resource for learning about how to write pure functional code.
A secondary downside is that it reduces the incentive for the compiler to optimise pure functional code, because it does not affect the core library.
score:5
When you have something like List
, which is used very often in nearly every Scala program:
even a very minor speedup (or slowdown) can have a large cumulative effect;
its contributors tend to be ones who know a lot about Scala low-level details (and if some don't, their patches will be reviewed by those who do).
So advice given to people just learning Scala isn't particularly applicable.
For this specific example: @tailrec
didn't exist until Scala 2.8, this code was probably written earlier (I haven't checked) and there is not sufficiently good reason to rewrite it.
Source: stackoverflow.com
Related Query
- What is the usage of a final var in Scala
- Scala lists "var" usage
- Scala var type usage results in type mismatch
- Use of def, val, and var in scala
- Why does Scala provide both multiple parameters lists and multiple parameters per list?
- Scala pattern matching on sequences other than Lists
- Scala with keyword usage
- Scala - convert List of Lists into a single List: List[List[A]] to List[A]
- Scala for loop over two lists simultaneously
- Usage of _ in scala lambda functions
- Scala Partition/Collect Usage
- Lists in Scala - plus colon vs double colon (+: vs ::)
- Scala transform list of tuples to a tuple of lists
- Scala - Two Lists to Tuple List
- Scala implicit usage choices
- Why don't Scala Lists have an Ordering?
- Combining two lists in Scala
- Scala overriding a non-abstract def with a var
- initialise a var in scala
- Correct usage of mutable/immutable lists
- comparing Scala lists with Java lists
- Is there example of scala abstract type usage which is impossible to achieve with generics?
- Why can't I assign to var in Scala subclass?
- Deep-reverse of nested lists in Scala
- Scala streams and their memory usage
- Scala - Combine two lists in an alternating fashion
- make a lazy var in scala
- Wildcard imports usage in Java and Scala
- pom configuration to force usage of jvm 7 with scala maven plugin
- Scala by name parameters with multiple argument lists and currying
More Query from same tag
- Scala Option[String] map turns in Iterable
- spark group by not getting type, mismatch error
- Averaging values at same position in List
- Use self type as return type in Scala trait
- What operations are performed in bulk when using parallel collections? Strange behavior here
- How to generate avro file using Scala
- Apache Spark - NoSuchMethodException: <Class>.<init>(java.lang.String) when copying custom Transformer
- Slick 3 - several db.run() calls in one transaction
- When not to use NotUsed in Akka Stream
- Add element error by scala/spark
- Akka - State management in routers
- how to parse nested json array in scala
- Exhaustive pattern matching when deprecated sealed trait instance present
- Converting timestamp format in dataframe
- Return option of member depending on option of containing object
- fs2 Stream from queue doesn't consume elements
- How to play with Specs matchers in Scala REPL?
- Running in issues after running Spark/scala job with single case id
- confusion in understanding of passing parameter in scala
- date time parse is not enforcing the format
- Scala - overloading operators for custom wrappers
- Multiplying event case class depending on the list based on nested IDs
- DStrream[String].foreachrdd on a Spark cluster
- How to add context bound TypeTags to types that take type parameters?
- WARN ScalaRowValueReader: Field 'client' is backed by an array but the associated Spark Schema does not reflect this
- Scala XML processing is skipping a value
- How do I display predictions, labels and dataframe column in Spark/Scala?
- Play framework and scala Convert List<T> for Json String
- I am not able to reach my sessions route, issue with my routing DSL code in my akka-http app
- Scala: How to override tuple equals() method for arbitrary element types?