/**
  * @inheritdoc
  */
 public function toDictionary($keySelector, $valueSelector = null)
 {
     $result = new Dictionary();
     $keyFunc = $this->resolveFunction($keySelector);
     $valueFunc = $this->resolveFunction($valueSelector);
     foreach ($this as $item) {
         $key = $keyFunc($item);
         if ($result->containsKey($key)) {
             throw new LogicException(sprintf('Key selection produces duplicated elements "%s".', $key));
         }
         $result->add($keyFunc($item), $valueFunc($item));
     }
     return $result;
 }
 public function testTryGetValue()
 {
     $value = null;
     $dictionary = new Dictionary(array('a' => 1, 'b' => 2, 'c' => 3));
     $this->assertEquals(false, $dictionary->tryGetValue('d', $value));
     $this->assertEquals(null, $value);
     $this->assertEquals(true, $dictionary->tryGetValue('b', $value));
     $this->assertEquals(2, $value);
 }