I don't think it makes sense to explicitly check on Stream because:

1. Not all streams are infinite
2. Not all infinite streams are %Stream{}

So we would have both false positives and false negatives. Also note this
problem happens with reduce, sum, count, etc.

On Thu, Sep 24, 2020 at 2:54 PM Devon Estes <[email protected]> wrote:

> I realized today that Enum.take_random/2 can enter an infinite loop if
> someone calls it with an unbounded Stream as the enum. I also see that
> there‘s a warning of sorts (although nothing expressly mentioning a Stream
> as an enum), but I‘m not sure this is going to address user confusion by
> this behavior.
>
> Would it make sense to emit a warning when using a Stream as an argument
> to take_random/2? Clearly since it‘s possible for this to _not_ get stuck
> in an infinite loop when using a steam we shouldn’t error, but a warning
> might at least help folks call something that converts the stream to a list
> before calling take_random/2.
>
> Thoughts?
> --
>
> _________________
> Devon Estes
> +49 176 2356 4717
> www.devonestes.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAGowJci%2BZ9hbg%3DVheXOqemF_PJ2YDQOn9aua0w-ejpYPHGnPwg%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGowJci%2BZ9hbg%3DVheXOqemF_PJ2YDQOn9aua0w-ejpYPHGnPwg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4LzxMd1_QVbpovvaV%3DM3-A9LU1vnc7C4LhT75teWrkqqg%40mail.gmail.com.

Reply via email to