elixir icon indicating copy to clipboard operation
elixir copied to clipboard

Stream reduce fails when take and drop are used together

Open pminten opened this issue 13 years ago • 0 comments

This doesn't work: Stream.drop(1..100, 5) |> Stream.take(5) |> Enum.to_list

** (ArgumentError) argument error
    lib/elixir/lib/stream.ex:118: Enumerable.Stream.Lazy.do_reduce/3
    lib/elixir/lib/enum.ex:1021: Enum.to_list/1
    erl_eval.erl:569: :erl_eval.do_apply/6
    src/elixir.erl:138: :elixir.eval_forms/3

These work:

  • Stream.drop(1..100, 5) |> Enum.take(5) |> Enum.to_list
  • Enum.drop(1..100, 5) |> Stream.take(5) |> Enum.to_list

This fails in an interesting way (after printing all the elements): Stream.drop(1..100, 5) |> Stream.take(5) |> Enum.each &IO.inspect/1

I suspect there's some issue in the base case of the recursion of do_reduce.

pminten avatar Aug 28 '13 12:08 pminten