IntIter is not an Iterator ??

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

IntIter is not an Iterator ??

Ian Martins
I don't think its a bug.  That's just how it is.  I think all iterators
should be iterable.  a cowardly code example...

   var a = Lambda.list(0...10);

is better than

   var a = new List<Int>();
   for( ii in 0...10 )
     a.add(ii);

whenever I write an iterator, I always include a

   function iterator() { return this; }

so it'll work with Lambda.

-Ian

> From: Lyndon Howie <[hidden email]>
> Subject: [haXe] IntIter is not an Iterator ??
> To: [hidden email]
>
> Hi,
> Maybe i'm doing it wrong but trying to use IntIters as an Iterator with
> Lambda's isn't working eg.
>
> Lambda.filter( { iterator : function() { return 0...10; }}, function(a) {
> return true;} ); //Fails to compile
>
> with the error:
> { iterator : Void -> IntIter } should be Iterable<Unknown<0>>
> { iterator : Void -> IntIter } should be { iterator : Void ->
> Iterator<Unknown<0>> }
> Invalid type for field iterator :
> Void -> IntIter should be Void -> Iterator<Unknown<0>>
> IntIter should be Iterator<Unknown<0>>
> IntIter should be { next : Void -> Unknown<0>, hasNext : Void -> Bool }
> For function argument 'it'
>
> But IntIter should be an Iterator<Int> as far as i can tell...? (All
> other iterators seem to work fine, from arrays, hash's etc.)
>
> Ok, as i was writing this an idea hit me, and if i explicitly set the
> iterator function return type it works eg.
> iterator : function() : Iterator<Int> { return 0...10; }
>
> Is it a bug that the type of IntIter isn't resolved correctly as an
> Iterator<Int> in this case?
>
> Cheers,
> Lyndon


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: IntIter is not an Iterator ??

Mark de Bruijn | Dykam
That is, IMO, extremely wrong behaviour. .iterator() expects a clean from-start iterator, this is quite the opposite, and as it's shared it can crash Lambda methods and alike.
--
Mark


On Thu, Aug 19, 2010 at 3:03 PM, Ian Martins <[hidden email]> wrote:
I don't think its a bug.  That's just how it is.  I think all iterators
should be iterable.  a cowardly code example...

  var a = Lambda.list(0...10);

is better than

  var a = new List<Int>();
  for( ii in 0...10 )
    a.add(ii);

whenever I write an iterator, I always include a

  function iterator() { return this; }

so it'll work with Lambda.

-Ian

> From: Lyndon Howie <[hidden email]>
> Subject: [haXe] IntIter is not an Iterator ??
> To: [hidden email]
>
> Hi,
> Maybe i'm doing it wrong but trying to use IntIters as an Iterator with
> Lambda's isn't working eg.
>
> Lambda.filter( { iterator : function() { return 0...10; }}, function(a) {
> return true;} ); //Fails to compile
>
> with the error:
> { iterator : Void -> IntIter } should be Iterable<Unknown<0>>
> { iterator : Void -> IntIter } should be { iterator : Void ->
> Iterator<Unknown<0>> }
> Invalid type for field iterator :
> Void -> IntIter should be Void -> Iterator<Unknown<0>>
> IntIter should be Iterator<Unknown<0>>
> IntIter should be { next : Void -> Unknown<0>, hasNext : Void -> Bool }
> For function argument 'it'
>
> But IntIter should be an Iterator<Int> as far as i can tell...? (All
> other iterators seem to work fine, from arrays, hash's etc.)
>
> Ok, as i was writing this an idea hit me, and if i explicitly set the
> iterator function return type it works eg.
> iterator : function() : Iterator<Int> { return 0...10; }
>
> Is it a bug that the type of IntIter isn't resolved correctly as an
> Iterator<Int> in this case?
>
> Cheers,
> Lyndon


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org