Range
Edit on GitHubUtilities for working with ranges.
A range represents an interval—a set of values with a beginning and an end.
All functions in this module treat ranges as exclusive, but inclusive versions
of all APIs are available in the Inclusive
submodule.
Added in 0.3.0
version | changes |
---|---|
0.6.0 | Treats all ranges as exclusive |
Values
Functions and constants included in the Range module.
Range.inRange
Added in 0.3.0
version | changes |
---|---|
0.6.0 | Treats all ranges as exclusive |
Checks if the given number is within the range.
Parameters:
param | type | description |
---|---|---|
value |
Number |
The number being checked |
range |
Range<Number> |
The range to check within |
Returns:
type | description |
---|---|
Bool |
Whether or not the value is within range |
Examples:
Range.forEach
Added in 0.3.0
version | changes |
---|---|
0.6.0 | Treats all ranges as exclusive |
Calls the given function with each number in the range.
For increasing ranges, the value is increased by 1
in each iteration,
and for decreasing ranges, the value is decreased by 1
. The value is
always changed by 1
, even if non-integer values were provided in the range.
Parameters:
param | type | description |
---|---|---|
fn |
Number => Void |
The function to be executed on each number in the range |
range |
Range<Number> |
The range to iterate |
Examples:
Range.map
Added in 0.3.2
version | changes |
---|---|
0.6.0 | Treats all ranges as exclusive |
Produces a list by calling the given function on each number included in the range.
For increasing ranges, the value is increased by 1
in each iteration,
and for decreasing ranges, the value is decreased by 1
. The value is
always changed by 1
, even if non-integer values were provided in the range.
Parameters:
param | type | description |
---|---|---|
fn |
Number => a |
The function called on each number in the range that returns the value for the output list |
range |
Range<Number> |
The range to iterate |
Returns:
type | description |
---|---|
List<a> |
A list containing all values returned from the fn |
Examples:
Range.Inclusive
Values
Functions and constants included in the Range.Inclusive module.
Range.Inclusive.inRange
Added in 0.6.0
version | changes |
---|---|
0.3.0 | Root APIs originally handled Inclusive & Exclusive variants |
Checks if the given number is within the range.
Parameters:
param | type | description |
---|---|---|
value |
Number |
The number being checked |
range |
Range<Number> |
The range to check within |
Returns:
type | description |
---|---|
Bool |
Whether or not the value is within range |
Examples:
Range.Inclusive.forEach
Added in 0.3.0
version | changes |
---|---|
0.3.0 | Root APIs originally handled Inclusive & Exclusive variants |
Calls the given function with each number in the range.
For increasing ranges, the value is increased by 1
in each iteration,
and for decreasing ranges, the value is decreased by 1
. The value is
always changed by 1
, even if non-integer values were provided in the range.
Parameters:
param | type | description |
---|---|---|
fn |
Number => Void |
The function to be executed on each number in the range |
range |
Range<Number> |
The range to iterate |
Examples:
Range.Inclusive.map
Added in 0.3.2
version | changes |
---|---|
0.3.0 | Root APIs originally handled Inclusive & Exclusive variants |
Produces a list by calling the given function on each number included in the range.
For increasing ranges, the value is increased by 1
in each iteration,
and for decreasing ranges, the value is decreased by 1
. The value is
always changed by 1
, even if non-integer values were provided in the range.
Parameters:
param | type | description |
---|---|---|
fn |
Number => a |
The function called on each number in the range that returns the value for the output list |
range |
Range<Number> |
The range to iterate |
Returns:
type | description |
---|---|
List<a> |
A list containing all values returned from the fn |
Examples: