gleam-lang / gleam-lang/stdlib

feat: range_with_step convenience function

Open
#887 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Gleam
Stars
710
Forks
225
Avg merge
5h 52m
Merged PRs (30d)
3

Description

I found myself needing to implement that function and thought that the usecase is popular enough to warrant [a PR](https://github.com/gleam-lang/stdlib/pull/886/files) stdlib.

This is a variation of range with the user-provided step.

The general use would be:
```
/// ```gleam
/// range_with_step(1, 5, 2)
/// // -> [1, 3, 5]
/// ```
///
/// ```gleam
/// range_with_step(1, 6, 2)
/// // -> [1, 3, 5]
/// ```
///
/// ```gleam
/// range_with_step(6, -1, -3)
/// // -> [6, 3, 0]
/// ```
///
/// ```gleam
/// range_with_step(6, -3, -3)
/// // -> [6, 3, 0, -3]
/// ```
```

Discussion (if the idea is not rejected):
- what should happen when given step is 0?
- what should happen when from and to are equal?
- which of the 2 above takes precedence?
- what should happen when (fromto and step>0)?
- a propos the one above should the function return `List(Int)` or `Result`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.