Skip to content

Stream reduce fails when take and drop are used together #1664

@pminten

Description

@pminten

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions