effusion v0.2.0 Effusion.Range View Source
Functions for working with Range
s.
Remember that ranges are inclusive, and 0..0
would have a length of 1
.
This module uses nil
to indicate a non-existent or invalid range.
Link to this section Summary
Functions
Find the range that is the overlap between two ranges.
Returns true
if the ranges a
and b
overlap; false
otherwise.
Find the length of the overlap between two ranges.
Returns the position within b, and length, of the overlapping section.
Creates a Range
from a starting value and a length.
Shift a range in one direction or another.
Link to this section Functions
Find the range that is the overlap between two ranges.
Examples
iex> Effusion.Range.overlap(0..5, 2..7)
2..5
iex> Effusion.Range.overlap(0..5, 5..10)
5..5
iex> Effusion.Range.overlap(0..3, 6..9)
nil
Returns true
if the ranges a
and b
overlap; false
otherwise.
Examples
iex> Effusion.Range.overlap?(0..5, 5..10)
true
iex> Effusion.Range.overlap?(0..1, 2..3)
false
Find the length of the overlap between two ranges.
Examples
iex> Effusion.Range.overlap_len(0..5, 2..7)
4
iex> Effusion.Range.overlap_len(0..5, 5..7)
1
iex> Effusion.Range.overlap_len(0..1, 2..3)
0
Returns the position within b, and length, of the overlapping section.
Examples
iex> Effusion.Range.overlap_poslen(0..10, 2..3)
{0, 2}
iex> Effusion.Range.overlap_poslen(4..5, 0..10)
{4, 2}
iex> Effusion.Range.overlap_poslen(0..1, 2..3)
{0, 0}
Creates a Range
from a starting value and a length.
Examples
iex> Effusion.Range.poslen(5, 5)
5..9
iex> Effusion.Range.poslen(0, 1)
0..0
Shift a range in one direction or another.
Examples
iex> Effusion.Range.shift(0..1, 3)
3..4
iex> Effusion.Range.shift(5..10, -5)
0..5