Lists—Not Arrays
Lists contain data and can be enumerated on. On the surface, they are similar to Ruby arrays, but there are pretty significant differences under the hood that result in totally different performance characteristics. As a result, you’ll use lists differently in Elixir than you would in Ruby.
In addition to lists, there’s a list alternative that throws a bit of a wrench at new Elixir programmers. You’ll learn about tuples and how they differ from lists. Don’t worry though, it’s a pretty straightforward difference.
The Basics
Lists are represented with the bracket [] syntax. You can easily create them, add to them, and work with them just as in Ruby. Enter the following code in an IEx session:
| $ iex |
| iex> list = [1, 2, 3] |
|
Get From Ruby to Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.