<?php
namespace nur\b\coll;

/**
 * Trait TIterableArray: implémentation des méthodes de base pour être un objet
 * array-like itérable. Ce trait doit être utilisé conjointement à
 * {@link TBaseArray}
 */
trait TIterableArray {
  private $valid;

  function _key() { return key($this->data); }
  function _current() { return current($this->data); }
  function rewind() {
    if ($this->data === null) {
      $this->valid = false;
    } else {
      $first = reset($this->data);
      $this->valid = $first !== false || key($this->data) !== null;
    }
  }
  function next() {
    $next = next($this->data);
    $this->valid = $next !== false || key($this->data) !== null;
  }
  function valid() { return $this->valid; }
}