Skip to content

Inconsistent behaviour of %Date.Range{} |> Enum.take/2 with negative amount #14746

@ryotsu

Description

@ryotsu

Elixir and Erlang/OTP versions

Elixir 1.18.4 (compiled with Erlang/OTP 28)

Operating system

x86_64 GNU/Linux

Current behavior

%Date.Range{} where the :first is after :last and a positive :step, when piped to Enum.take/2 with a negative amount does not terminate. For example:

Date.range(~D[2025-09-22], ~D[2025-09-21], 1) 
|> Enum.take(-1)

Expected behavior

Date.range(~D[2025-09-22], ~D[2025-09-21], 1) 
|> Enum.take(-1)

should return an empty list [], similar to

Enum.take(2..1//1, -1)

or

Date.range(~D[2025-09-22], ~D[2025-09-21], 1) 
|> Enum.to_list()
|> Enum.take(-1)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions