Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a list with 100 1s in Scala 2.9

In earlier versions of Scala you can use List.make(100, 1), but that is now deprecated. What is the new proper way to do it?

like image 279
placeybordeaux Avatar asked Jun 08 '12 17:06

placeybordeaux


People also ask

How do I add a list to a list in Scala?

This is the first method we use to append Scala List using the operator “:+”. The syntax we use in this method is; first to declare the list name and then use the ':+' method rather than the new element that will be appended in the list. The syntax looks like “List name:+ new elements”.

What does this symbol => Do in Scala?

Show activity on this post. => is the "function arrow". It is used both in function type signatures as well as anonymous function terms. () => Unit is a shorthand for Function0[Unit] , which is the type of functions which take no arguments and return nothing useful (like void in other languages).

How do you concatenate lists in Scala?

In order to concatenate two lists we need to utilize concat() method in Scala. In above syntax, l1 is list1 and l2 is list2.

Is Scala list a seq?

In Java terms, Scala's Seq would be Java's List , and Scala's List would be Java's LinkedList . Note that Seq is a trait , which is equivalent to Java's interface , but with the equivalent of up-and-coming defender methods.


2 Answers

As described in the deprecated note:

@deprecated("use `fill' instead", "2.8.0")

try this:

List.fill(100)(1)
like image 78
Tomasz Nurkiewicz Avatar answered Oct 09 '22 20:10

Tomasz Nurkiewicz


As the documentation says:

  List.fill(100)(1)
like image 29
Giovanni Caporaletti Avatar answered Oct 09 '22 21:10

Giovanni Caporaletti