Is there any utility function in Elixir from which I want to get sublist from array based on index and size?
Enum utility doesn't provide this functionality
arr = [1,2,3,4,5,6,7]
from=2
size=3
res = sublist(arr,from,size)
#res should return [3,4,5]
You can use Enum.slice/3 like this:
[1,2,3,4,5,6,7] |> Enum.slice(2, 3)
[3, 4, 5]
Or without the pipe operator like this:
Enum.slice([1,2,3,4,5,6,7], 2, 3)
[3, 4, 5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With