Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an infinite enumerable still "enumerable"?

Like two overlapping line segments, we can find infinite points of intersection. To enumerate all these points might not make sense, and we might just want to present that this collection is infinity.

Floating point numbers have defined NegativeInfinity and PositiveInfinity. A number which represents count or ordinal seem not necessary to use floating point numbers, however, integers are not defined something to represent infinity.

So I tried to implement an infinite enumerable. But I suddenly get confused with the term "enumerable" ..

Is there a better way to solve this problem? And is an infinite enumerable still enumerable?

  • Code

    public partial class Infinity: IEnumerable<object> {
        IEnumerator<object> IEnumerable<object>.GetEnumerator() {
            for(; ; )
                yield return Infinity.Enumerable;
        }
    
        public IEnumerator GetEnumerator() {
            for(; ; )
                yield return Infinity.Enumerable;
        }
    
        public Infinity LongCount(
            Func<object, bool> predicate=default(Func<object, bool>)) {
            return Infinity.Enumerable;
        }
    
        public Infinity Count(
            Func<object, bool> predicate=default(Func<object, bool>)) {
            return Infinity.Enumerable;
        }
    
        public static readonly Infinity Enumerable=new Infinity();
    }
    

Edit:

Thanks for answering. I'm not confused with IEnumerable and IEnumerator. GetEnumerator methods return Infinity.Enumerable is because I do not want to declare an extra dummy object such as:

static readonly object dummy=new object();

and yield return dummy in GetEnumerator methods.

like image 729
Ken Kin Avatar asked Dec 20 '22 05:12

Ken Kin


1 Answers

And is an infinite enumerable still enumerable?

Enumerable, in this sense, is based off the second definition of enumerate:

to specify one after another

It is not referring to the (more common outside of computing) definition whereby it effectively means "able to be counted."

In this sense, an infinite series can definitely be listed one item after another, and qualifies as an enumerable.

That being said, I don't see the purpose behind your code in this example. Infinite enumerables are typically representing something like a stream of data without an end, or other sources where there is no "end", but the potential to continually pull information.

like image 200
Reed Copsey Avatar answered Jan 02 '23 17:01

Reed Copsey