Skip to content

Add a range/step/seq function #1039

@alco

Description

@alco

Something akin to Python's range could make a nice addition to the language as a library or builtin function.

>>> range(0, 8, 2)
[0, 2, 4, 6]
>>> range(3, 5, -1)
[]
>>> range(-3, -5, -1)
[-3, -4]

It would produce an iterable, not a list.

Related discussion on the mailing list https://groups.google.com/forum/?fromgroups=#!topic/elixir-lang-core/HpBIV5zMAHw , continued in the issue #1017.

Both step and seq are OK names. Altough, as another alternative, we could rename current ranges to intervals (it makes just as much sense to talk about inclusiveness and non-inclusiveness of intervals, aka closed intervals and open intervals) and call the new function range.

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