elixir append lists
To append lists in Elixir, you can use the ++
operator or the List.concat/1
function. Here's how you can do it:
Using the ++
operator:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = list1 ++ list2
In this example, result
will be [1, 2, 3, 4, 5, 6]
.
Using the List.concat/1
function:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = List.concat([list1, list2])
In this example, result
will also be [1, 2, 3, 4, 5, 6]
.
Both methods achieve the same result of appending two lists together. You can choose the method that suits your preference or the specific requirements of your code.
[[SOURCE 1]]