4 Replies - 1350 Views - Last Post: 13 November 2012 - 06:23 AM Rate Topic: -----

#1 [RTS]BN+VS*  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 175
  • Joined: 23-March 09

ArrayObject from Iterator

Posted 11 October 2012 - 07:03 AM

Currently I have this code

$statements = new ByPropertyIdArray( iterator_to_array( $statements ) );


Where ByPropertyIdArray extends ArrayObject.

The problem I have with this is that I have an Iterator (which happens to be an ArrayObject) that I want to construct a new ByPropertyIdArray from (which is an Iterator) but that in the process it gets turned into an array. Iterator => array => Iterator is stupid.

I could ofc just loop over the Iterator and call append in the loop, but this is also not ideal.

Is there no nice and performant way to go from Iterator (or at least ArrayObject) to ArrayObject?

Is This A Good Question/Topic? 0
  • +

Replies To: ArrayObject from Iterator

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: ArrayObject from Iterator

Posted 11 October 2012 - 07:21 AM

Quote

Is there no nice and performant way to go from Iterator (or at least ArrayObject) to ArrayObject?

I don’t think so, because both serve totally different purposes (iterating vs. "array API")


Quote

The problem I have with this is that I have an Iterator (which happens to be an ArrayObject) that I want to construct a new ByPropertyIdArray from (which is an Iterator) but that in the process it gets turned into an array. Iterator => array => Iterator is stupid.

doesn’t Iterator and ArrayObject somewhat excludes each other (I mean, ArrayObject implements IteratorAggregate, which returns an Iterator to loop over)?

next, what input types does ByPropertyIdArray accept? if it only accepts (plain) arrays, there is no way to get around that (unless, of course, you modify the constructor).

however, you can tell the ArrayObject to use a certain iterator class (constructor’s 3rd parameter).

This post has been edited by Dormilich: 11 October 2012 - 07:22 AM

Was This Post Helpful? 0
  • +
  • -

#3 [RTS]BN+VS*  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 175
  • Joined: 23-March 09

Re: ArrayObject from Iterator

Posted 11 October 2012 - 08:16 AM

Thanks for your reply.

Quote

doesnít Iterator and ArrayObject somewhat excludes each other (I mean, ArrayObject implements IteratorAggregate, which returns an Iterator to loop over)?


Ok, error in my phrasing of the question. Replace Iterator by Traversable.

Quote

I donít think so, because both serve totally different purposes (iterating vs. "array API")


Sure, I don't object to not having a Traversable to ArrayObject thing, but ArrayObject (or similar) to ArrayObject (or similar) does make sense no?

Quote

next, what input types does ByPropertyIdArray accept? if it only accepts (plain) arrays, there is no way to get around that (unless, of course, you modify the constructor).


Not sure what you mean with "input types". It can contain values of any type. I am not looking to restrict this.

Quote

however, you can tell the ArrayObject to use a certain iterator class (constructorís 3rd parameter).


I know, but this is not relevant to my problem as far as I can see.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: ArrayObject from Iterator

Posted 11 October 2012 - 10:58 PM

Quote

BN+VS*' date='11 October 2012 - 05:16 PM' timestamp='1349968600' post='1720987']
Not sure what you mean with "input types". It can contain values of any type. I am not looking to restrict this.

in other words, what constraints does the ByPropertyIdArray constructor have on its parameters? from the code snippet I can see that it accepts array, thatís all the info you have given me.


Quote

BN+VS*' date='11 October 2012 - 05:16 PM' timestamp='1349968600' post='1720987']
I don't object to not having a Traversable to ArrayObject thing, but ArrayObject (or similar) to ArrayObject (or similar) does make sense no?

your explanation sounded different than that. creating an ArrayObject from another ArrayObject is possible in theory, though in reality it depends on your implementation (and since I donít know that ...).
Was This Post Helpful? 0
  • +
  • -

#5 [RTS]BN+VS*  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 175
  • Joined: 23-March 09

Re: ArrayObject from Iterator

Posted 13 November 2012 - 06:23 AM

Anyone got an answer to my question, or wants some specific clarification not already provided?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1