We had a recent refactoring case that led us to wonder what the difference between Enum.take_while/2 and Stream.take_while/2 is.
Here is a nice explanation of how Enum functions (the example was Enum.reduce_while/2) don’t actually hold the whole collection in the memory unless the final output of the function contains it.
So it seems to us that unless the take_while/2 is called in the middle of a chain of transformations on a stream (instead of as the last transformation), the Enum version and the Stream version should actually behave the same? Or maybe this understanding is not correct.
If Stream.take_while is immediately followed by a non-lazy function that needs all the stream values (like Enum.to_list) then there shouldn’t be any notable difference.