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); }
public function __construct($fnPrev = null) { if (!$fnPrev) { $fnPrev = FnGen::fnIdentity(); } $this->fnToApply = function ($values) use($fnPrev) { return Sequence::make($fnPrev($values)); }; }
/** * @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; }
/** * @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())); }
/** * 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())); }
public function testFnIdentity() { $fn = FnGen::fnIdentity(); $this->assertTrue($fn(99) === 99); $this->assertTrue($fn("hello") === "hello"); }