Enum.to_list/1 vs Enum.into/2

Just curious, but could someone explain the difference between Enum.to_list 1..5 and Enum.into 1..5, []? I understand that the latter is converting that range into a collectable, but if I’m not mistaken, the former is also transforming the range into a collectable since lists are collectables(?).

This isn’t really super important or integral to any projects I’m currently working on, I’m just curious if there is something else going on under the hood that differentiates those two specific lines of code. Also, I’m talking about Enum.into/2, not Enum.into/3.


Enum.into/2 can convert to other collectibles and it need to do dynamic dispatch. Other than that I would say that Enum.to_list/1 is clearer in the intention than Enum.into(_, []) when you always collect into list.

The source is highly informative here :slight_smile: :