在Elixir列表中,如何获得中间值?

Yin*_*gce 3 elixir

我需要从列表中获取中间值.

如何使用list[0]或使用list[3..-1]灵丹妙药?

例如:

 list = [1,2,3,4,5,6]
 list[0] [1]
 list[2..-1] [3,4,5,6]
Run Code Online (Sandbox Code Playgroud)

以及如何使用它Tuple

Ker*_*ael 9

使用Enum.slice/2你可以做:

Enum.slice(list, 2..-1) # [3, 4, 5, 6]
Run Code Online (Sandbox Code Playgroud)

而且Enum.take/2:

Enum.take(list, 1) # [1]
Run Code Online (Sandbox Code Playgroud)