Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jw3126/rangehelpers.jl
Make ranges not bugs
https://github.com/jw3126/rangehelpers.jl
julia ranges
Last synced: 3 months ago
JSON representation
Make ranges not bugs
- Host: GitHub
- URL: https://github.com/jw3126/rangehelpers.jl
- Owner: jw3126
- License: mit
- Created: 2020-10-14T14:08:58.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-21T18:05:28.000Z (about 1 year ago)
- Last Synced: 2024-10-11T22:56:19.103Z (3 months ago)
- Topics: julia, ranges
- Language: Julia
- Homepage:
- Size: 178 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RangeHelpers
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://jw3126.github.io/RangeHelpers.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://jw3126.github.io/RangeHelpers.jl/dev)
[![Build Status](https://github.com/jw3126/RangeHelpers.jl/workflows/CI/badge.svg)](https://github.com/jw3126/RangeHelpers.jl/actions)
[![Build Status](https://travis-ci.com/jw3126/RangeHelpers.jl.svg?branch=master)](https://travis-ci.com/jw3126/RangeHelpers.jl)
[![Coverage](https://codecov.io/gh/jw3126/RangeHelpers.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jw3126/RangeHelpers.jl)Ever needed a range with startpoint 10, endpoint 121.7 and a step of 25?
Well that is mathematically not possible, so you need to compromise.
There are lots of options, you could relax the startpoint, endpoint or step. In the past doing this was annoying and prone to off-by-one-errors:
```julia
julia> Base.range(10, step=25, length=round(Int, (121.7-10)/25)); # is it correct??
```
[RangeHelpers.jl](https://github.com/jw3126/RangeHelpers.jl) aims to solve range construction headaches once and for all:
```julia
julia> using RangeHelpers: rangejulia> using RangeHelpers
julia> range(start = 10, stop = 121.7, step = around(25)) # compromise on step
10.0:27.925:121.7julia> range(start = 10, stop = 121.7, step = ≤(25)) # compromise step at most 25
10.0:22.34:121.7julia> range(start = 10, stop = ≥(121.7), step = 25) # exact step, but allow bigger endpoint
10:25:135julia> anchorrange(42, start = around(10), step = 25, stop = around(121.7)) # make sure 42 is on the grid
17:25:117
```
See [the documentation](https://jw3126.github.io/RangeHelpers.jl/dev/) for even more ways to make ranges.