Scala shortest equivalent to c# LINQ
c#, collections, linq, loops, scala
Solution
Use List.range:
List.range(1, n + 1).map(new Person(_))
Or as Lee suggested:
(1 to n).map(new Person(_)).toList
Calling `toList` is required because `(1 to n).map(new Person(_))` produces an `IndexedSeq[Person]`. Note also that the type of `1 to n` is `Range.Inclusive` and that it is different to the type of `List.range(1, n + 1)` which is `List[Int]`.
Problem
I need to create a bunch of new objects in scala What is the shortest equivalent for the following C# code? ``` var n = 100; var persons = Enumerable.Range(1, n).Select(x=>new Person(x)).ToList(); ``` and whats wrong with this? ``` val persons: List[Person] = (1 to n) map (new Person(_)) ```