HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.16k stars 656 forks source link

Issue 342 - Lambda.count<A> is semantically erroneous (too broad) - haxe #342

Closed issuesbot closed 11 years ago

issuesbot commented 11 years ago

[Google Issue #342 : https://code.google.com/p/haxe/issues/detail?id=342] by she...@coolpage.com, at 09/02/2011, 08:21:04 An Iterable is not always countable, because it may not be rewinded or reset on Iterable.iterator(), e.g. a subclass which reads from a stream and does not cache the elements read from the stream.

The semantic of countable belongs in a container, which is a subset of the Iterable category. Iterable means anything that can be enumerated, but that does not imply that everything that can be enumerated must also be collected (i.e. cached or contained).

In short, count should not operate on an Iterable, but rather on a container interface which inherits from Iterable.

issuesbot commented 11 years ago

[comment from she...@coolpage.com, published at 10/02/2011, 09:12:59] Ditto Lambda.concat. Although it is semantically meaningful to chain Iterables, the output should not be a List, rather instead should output an Iterable which chains the inputs. The reason is because an Iterable is not always a container (collection), and can be sometimes a stream. The count() and concat() would never return on a stream Iterable, if those streams are open-ended (e.g. a streaming live webcam session).

issuesbot commented 11 years ago

[comment from ncanna...@gmail.com, published at 10/02/2011, 09:39:14]

issuesbot commented 11 years ago

[comment from she...@coolpage.com, published at 10/02/2011, 09:51:29] Ditto Lamdba.array, filter, fold, foreach, iter, list, and map. None of these are legal on Iterable, only on a container interface which inherits from Iterable.

Only functions that can terminate before iterator.hasNext() == false are legal on Iterable, e.g. some and every (Lambda doesn't have these).

So the entire Lambda is semantically too broad, because it assume the Iterables are also containers. But Iterable is broader than than a container, it can also include streams that never terminate, i.e. hasNext() always true (or very long time).

issuesbot commented 11 years ago

[comment from she...@coolpage.com, published at 10/02/2011, 10:15:34] Lambda does have "exists" which is like "some":

http://code.google.com/p/haxe/issues/detail?id=227#c2