/**
  * Initializes a new instance of that class.
  *
  * @param IEnumerable $seq The inner sequence.
  * @param callable $keySelector The key selector to use.
  * @param callable $valueSelector The value / item selector to use.
  *
  * @throws ArgumentNullException $keySelector is (null).
  */
 public function __construct(IEnumerable $seq, $keySelector, $valueSelector)
 {
     if (null === $valueSelector) {
         throw new ArgumentNullException('valueSelector');
     }
     $this->_valueSelector = Object::asCallable($valueSelector);
     parent::__construct($seq, $keySelector);
 }
Exemplo n.º 2
0
 /**
  * Initializes a new instance of that class.
  *
  * @param IEnumerable $seq The inner sequence.
  * @param callable $keySelector The key selector to use.
  *
  * @throws ArgumentException $keySelector is no valid callable / lambda expression.
  * @throws ArgumentNullException $keySelector is (null).
  */
 public function __construct(IEnumerable $seq, $keySelector)
 {
     if (null === $keySelector) {
         throw new ArgumentNullException('keySelector');
     }
     $this->_keySelector = Object::asCallable($keySelector);
     $this->_seq = $seq;
 }
Exemplo n.º 3
0
    public function testWithNoArguments()
    {
        $lambdas = ['=> 78.9', '() => 78.9', ' => return 78.9;', '() => return 78.9;', ' => { return 78.9; }', '() => { return 78.9; }', ' => {
return 78.9;
}', '() => {
return 78.9;
}'];
        foreach ($lambdas as $l) {
            $func = Object::toLambda($l);
            $this->assertSame(78.90000000000001, $func());
        }
    }
Exemplo n.º 4
0
 public function testValueWrapper2()
 {
     $wrapperTypes = [IValueWrapper::class, new ReflectionClass(IValueWrapper::class), ValueWrapper::class, new ReflectionClass(ValueWrapper::class)];
     foreach ($wrapperTypes as $targetType) {
         /* @var IValueWrapper $obj1 */
         /* @var IValueWrapper $obj2 */
         /* @var IValueWrapper $obj3 */
         /* @var IValueWrapper $obj4 */
         $rc = $targetType;
         if (!$rc instanceof ReflectionClass) {
             $rc = new ReflectionClass($rc);
         }
         $val1 = '1';
         $val2 = 2;
         $val3 = 3.0;
         $val4 = 4.5;
         $obj1 = Object::convertTo($val1, $targetType);
         $obj2 = Object::convertTo($val2, $targetType);
         $obj3 = Object::convertTo($val3, $targetType);
         $obj4 = Object::convertTo($val4, $targetType);
         $this->assertInstanceOf(IValueWrapper::class, $obj1);
         $this->assertInstanceOf($rc->getName(), $obj1);
         $this->assertSame($val1, $obj1->getWrappedValue());
         $this->assertInstanceOf(IValueWrapper::class, $obj2);
         $this->assertInstanceOf($rc->getName(), $obj2);
         $this->assertSame($val2, $obj2->getWrappedValue());
         $this->assertInstanceOf(IValueWrapper::class, $obj3);
         $this->assertInstanceOf($rc->getName(), $obj3);
         $this->assertSame($val3, $obj3->getWrappedValue());
         $this->assertInstanceOf(IValueWrapper::class, $obj4);
         $this->assertInstanceOf($rc->getName(), $obj4);
         $this->assertSame($val4, $obj4->getWrappedValue());
     }
 }