

The book Programming in Scala shows how to create a List using a simple "squares" function: The tabulate method creates a new List whose elements are created according to the function you supply. X: List = List(foo, foo, foo)įinally, you can create a new List with the tabulate method of the List class.

You can also create a new List with its fill method: The range function can also take a third argument which serves as a "step" value when creating the List: You can also create a List with its range method: In this example, I'm explicitly saying that I want the values in the List to be saved as the Number type. If you're mixing types in a List constructor, you may need to manually specify the List type. As you can see, Scala can usually infer the type of a List very well.The :: method takes two arguments, a "head", which is a single element, and a "tail", which is a List.The first approach shows the "cons" syntax, which, as I mentioned, is the Lisp style of creating a list.Here's the Java-style approach to creating a Scala List: Here's the Lisp-style approach to creating a List: You can create a Scala List object in several different way.
#Xlist latex letter update#
(I need to update this, but this is the Scala class hierarchy, as shown by the current Scala API documentation.
