Exemplo n.º 1
0
 public function testFnRevComp()
 {
     $range = range(1, 100);
     $rangeReverse = array_reverse($range);
     // Check the values are sorted.
     $result = $range;
     usort($result, FnSort::fnRevComp(FnGen::fnIdentity()));
     $this->assertEquals($rangeReverse, $result);
 }
Exemplo n.º 2
0
 public function __construct($fnPrev = null)
 {
     if (!$fnPrev) {
         $fnPrev = FnGen::fnIdentity();
     }
     $this->fnToApply = function ($values) use($fnPrev) {
         return Sequence::make($fnPrev($values));
     };
 }
Exemplo n.º 3
0
 /**
  * @param Iterator      $iterator
  * @param callable|null $fnMapValueFunction($value, $key)
  * @param callable|null $fnMapKeyFunction($key, $value)
  */
 public function __construct(Iterator $iterator, $fnMapValueFunction, $fnMapKeyFunction)
 {
     parent::__construct($iterator);
     if (!$fnMapKeyFunction) {
         $fnMapKeyFunction = FnGen::fnIdentity();
     }
     if (!$fnMapValueFunction) {
         $fnMapValueFunction = FnGen::fnIdentity();
     }
     $this->fnMapValueFunction = $fnMapValueFunction;
     $this->fnMapKeyFunction = $fnMapKeyFunction;
 }
Exemplo n.º 4
0
 /**
  * @param Iterator $iterator
  * @return MappedSequence
  */
 public static function sequenceNumericKeys(Iterator $iterator)
 {
     return new MappedSequence($iterator, FnGen::fnIdentity(), FnGen::fnIfMap(FnGen::fnIsNumeric(), FnGen::fnCounter(), FnGen::fnIdentity()));
 }
Exemplo n.º 5
0
 /**
  * Returns the key of the first element where $fnTest returns true.
  *
  * @param callable|null $fnTest($value, $key)
  * @return mixed
  */
 public function firstKey($fnTest = null)
 {
     $fnTest = $fnTest ?: fn\fnTrue();
     return $this->filter($fnTest)->limit(1)->keys()->reduce(null, FnGen::fnSwapParamsPassThrough(FnGen::fnIdentity()));
 }
Exemplo n.º 6
0
 public function testFnIdentity()
 {
     $fn = FnGen::fnIdentity();
     $this->assertTrue($fn(99) === 99);
     $this->assertTrue($fn("hello") === "hello");
 }