Exemple #1
0
 public function __construct($seq, $aSeq)
 {
     $iterator = null;
     $itAppend = new AppendIterator();
     if (!is_null($seq)) {
         $iterator = Sloth::iter($seq);
         $itAppend->append($iterator);
     }
     foreach ($aSeq as $mSeq) {
         $itAppend->append(Sloth::iter($mSeq));
     }
     $this->iterator = $itAppend;
 }
Exemple #2
0
 public function __construct($seq, $offset = 0, $count = -1)
 {
     $iterator = Sloth::iter($seq);
     $itLimit = new LimitIterator($iterator, $offset, $count);
     $this->iterator = $itLimit;
 }
Exemple #3
0
 public function __construct($seq)
 {
     $itNoRewind = new NoRewindIterator(Sloth::iter($seq));
     $this->iterator = $itNoRewind;
 }
Exemple #4
0
 /**
  * iter
  * @param mixed $mFirst
  * @param func $fnCallback
  * @return object Sloth_Iterator
  */
 public static function iter($mFirst, $fnCallback = null)
 {
     if (is_null($fnCallback)) {
         if (is_array($mFirst)) {
             return new Sloth_Iterator($mFirst);
         } else {
             if ($mFirst instanceof Sloth_IteratorInterface) {
                 return $mFirst;
             } else {
                 if ($mFirst instanceof Iterator) {
                     return new Sloth_Iterator($mFirst);
                 } else {
                     if ($mFirst instanceof IteratorAggregate) {
                         $iter = $mFirst->getIterator();
                         if ($iter instanceof Sloth_IteratorInterface) {
                             return $iter;
                         } else {
                             if ($iter instanceof Iterator) {
                                 return new Sloth_Iterator($iter);
                             }
                         }
                     } else {
                         throw new InvalidArgumentException();
                     }
                 }
             }
         }
     } else {
         if (is_int($fnCallback)) {
             return Sloth::ref(new Sloth_Follow($mFirst, Sloth::fn('$x+1')))->take($fnCallback);
         } else {
             return new Sloth_Follow($mFirst, $fnCallback);
         }
     }
 }
Exemple #5
0
 public function getIterator()
 {
     return Sloth::iter(new ArrayIterator($this->_data));
 }
Exemple #6
0
 static function scanDirIter($path, $order = 0, $sort = 'name', $context = null)
 {
     $files = self::scandir($path, $order, $sort, $context);
     return Sloth::iter($files);
 }
Exemple #7
0
        return $this->is_valid;
    }
    function next()
    {
        $result = call_user_func($this->fn, $this->current_value, ++$this->key);
        if ($result === false) {
            $this->is_valid = false;
        } else {
            $this->current_value = $result;
        }
    }
    function current()
    {
        return $this->current_value;
    }
    function key()
    {
        return $this->key;
    }
    function rewind()
    {
        $this->key = 0;
        $this->current_value = $this->first;
        $this->is_valid = true;
    }
}
//
// DocTest
//
!count(debug_backtrace()) and Sloth::doctest(__FILE__);
Exemple #8
0
 public function __construct($seq, $callback)
 {
     $iterator = Sloth::iter($seq);
     $itFilter = new Sloth_CallbackFilterIterator($iterator, $callback);
     $this->iterator = $itFilter;
 }
Exemple #9
0
 public function __construct($seq)
 {
     $iterator = Sloth::iter($seq);
     $itInfin = new InfiniteIterator($iterator);
     $this->iterator = $itInfin;
 }
Exemple #10
0
 function iter($sql, $params = null, $strict = null)
 {
     $strict = is_null($strict) ? $this->strict() : $strict;
     list($sql, $params) = $this->prepareSql($sql, $params);
     $this->log($sql, $params);
     return Sloth::iter(Gongo_Locator::get($this->iteratorClass(), $this->pdo(), $sql, $params, PDO::FETCH_ASSOC, $strict));
 }
Exemple #11
0
 function parseFileIter($path)
 {
     return Sloth::iter(new SplFileObject($path))->map(array($this, 'parseLine'));
 }