Skip to content
getWhole methods. authored by Santiago Yépez's avatar Santiago Yépez
# The `Range` class
## `getWhole` method
### Description
It creates and returns a `Range` object whose minimum and maximum stamps are respectively the lowest of and the greatest of the stamps among those stored by two `Range` objects.
**Type:** Static
```perl
my $range = Range->getWhole($range1, $range2, $trimFunction);
```
### Arguments
| Name | Description | Mandatoriness | Default value |
| ----------------------- | ------------------------------------------------------------ | ------------- | ------------- |
| `$range1` and `$range2` | `Range` object from which to retrieve the minimum and maximum stamps to build the resulting `Range` object. See **Note 1**. | Optional | |
| `$trimFunction` | `CODE` reference for trimming decimals, to be applied on the resulting `Range` object. See **Note 2**. | Optional | |
**Note 1:** If `undef` takes the place of both `$range1` and `$range2` arguments, then `getWhole` will return `undef`, on the other hand, if `undef` takes the place of just one of them, the stamps of the other one will be used to build the resulting `Range` object.
**Note 2:** The `$trimFunction` argument is used to build the resulting `Range` object only when none of `$range1` and `$range2` are `undef`.
### Samples
-----
**I 1:**
```perl
### `CODE` reference for trimming decimals.
my $trimFunction = sub { return 0 + sprintf '%.2f', shift; };
### Create some `Range` objects from whose stamps
### the resulting `Range` object will be built.
my $range1 = Range->new(5, 10);
my $range2 = Range->new(15, 20.33333);
### Call the `getWhole` method
### with the above `Range` objects as arguments
### and print the resulting `Range` object.
my $range3 = Range->getWhole($range1, $range2, $trimFunction);
print "Range: " . $range3->toString;
```
**O 1:**
```
Range: 5 -> 20.33
```
Download [snippet](https://gitlab.com/SantiagoYepez/RangeHandling/snippets/1830894).
-----
\ No newline at end of file