private function update_current_iterator()
 {
     $this->current_iterator = $this->chain->valid() ? Crankshaft::ToIterator($this->chain->current()) : null;
     if ($this->current_iterator !== null) {
         $this->current_iterator->rewind();
     }
 }
 public function setup()
 {
     $this->seen = Crankshaft::Set();
     $this->inner_iterator->rewind();
 }
Example #3
0
 public function __construct($traversable, $map_fn)
 {
     Crankshaft::AssertCallable($map_fn);
     parent::__construct($traversable);
     $this->map_fn = $map_fn;
 }
Example #4
0
 /**
  * Internal: Used to implement max() and min().
  */
 private function optimal($is_better_fn, $key_fn = null)
 {
     Crankshaft::AssertCallable($is_better_fn);
     if ($key_fn === null) {
         $key_fn = 'Thumbtack\\Crankshaft\\Crankshaft::Identity';
     } else {
         Crankshaft::AssertCallable($key_fn);
     }
     $initializing = true;
     $result = null;
     $best_key = null;
     foreach ($this as $value) {
         $key = call_user_func($key_fn, $value);
         if ($initializing) {
             $initializing = false;
             $current_value_is_better = true;
         } else {
             $current_value_is_better = call_user_func($is_better_fn, $best_key, $key);
         }
         if ($current_value_is_better) {
             $result = $value;
             $best_key = $key;
         }
     }
     if ($initializing) {
         throw new EmptyIterableError('Cannot take the max or min of an empty iterable.');
     }
     return $result;
 }
 public function __construct(\Iterator $iterator, $filter_fn)
 {
     Crankshaft::AssertCallable($filter_fn);
     parent::__construct($iterator);
     $this->filter_fn = $filter_fn;
 }