Infinite Ranges and Functions that Return Ranges
In this lesson, you will learn about infinite ranges and the functions that return ranges.
We'll cover the following
Infinite ranges
Another benefit of not storing elements as actual members is the ability to create infinite ranges.
Making an infinite range is as simple as having empty
always return false
. Since it is constant, empty
need not even be a function and can be defined as an enum
value:
enum empty = false; // ← infinite range
Another option is to use an immutable static member:
static immutable empty = false; // same as above
As an example of this, let’s design a range that represents the Fibonacci series. Despite having only two int
members, the following range can be used as the infinite Fibonacci series:
Get hands-on with 1400+ tech skills courses.