Enum.slice/2
defmodule Enum do
def slice(enumerable, range)
end
Returns a subset list of the given enumerable by range
.
range
must be a Range
. Given an enumerable
, it drops elements before range.first
(zero-base), then takes elements until element range.last
(inclusively).
If range.last
is out of bounds, then it is assigned as the index of the last element.
Indexes are normalized, meaning that negative indexes will be counted from the end.
If the normalized range.first
is out of bounds of the given enumerable, or this one is greater than the normalized range.last
, then []
is returned.