I do not believe that there is any “more idiomatic” way to do this. I do not know the built-in method for this.
One suggestion - if you are dealing with larger lists, you might be better off using Stream rather than Enum.
list = [1,2,3,4,5,6,7,8,9] s = Stream.take_every(list,2) l2 = Enum.to_list(s)
And then
l1 = list -- l2
You better use Stream where you can, because Stream is lazily priced. In this particular case, this will not be affected. But in some cases, lazy appreciation can really speed up the process.
As I said, my code is no more idiomatic than your solution, and this is certainly not a built-in function.
source share