Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7187910
PhutilChunkedIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilChunkedIterator.php
View Options
<?php
/**
* This is an iterator version of `array_chunk()`.
*/
final
class
PhutilChunkedIterator
extends
Phobject
implements
Iterator
{
private
$iterator
;
private
$size
;
private
$key
=
0
;
private
$current
;
/**
* @param Iterator
* @param int
*/
public
function
__construct
(
Iterator
$iterator
,
$size
)
{
$this
->
iterator
=
$iterator
;
$this
->
size
=
$size
;
}
public
function
rewind
()
{
$this
->
iterator
->
rewind
();
$this
->
next
();
$this
->
key
=
0
;
}
/**
* @return int
*/
public
function
key
()
{
return
$this
->
key
;
}
/**
* @return array
*/
public
function
current
()
{
return
$this
->
current
;
}
public
function
next
()
{
$this
->
current
=
array
();
while
(
$this
->
iterator
->
valid
())
{
$key
=
$this
->
iterator
->
key
();
$this
->
current
[
$key
]
=
$this
->
iterator
->
current
();
$this
->
iterator
->
next
();
if
(
count
(
$this
->
current
)
>=
$this
->
size
)
{
break
;
}
}
$this
->
key
++;
}
public
function
valid
()
{
return
(
bool
)
$this
->
current
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Jul 8, 07:42 (9 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
736799
Default Alt Text
PhutilChunkedIterator.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment