Esempio n. 1
0
 /** {@inheritdoc} */
 public function offsetSet($offset, $value)
 {
     if (!is_array($value)) {
         throw new \InvalidArgumentException(self::ERROR_LOOKUP_VALUE_NOT_ARRAY);
     }
     parent::offsetSet($offset, $value);
 }
Esempio n. 2
0
 /**
  * <p><b>Syntax</b>: toDictionary ([keySelector {{(v, k) ==> key} [, valueSelector {{(v, k) ==> value}]])
  * <p>Creates a {@link Dictionary} from a sequence according to specified key selector and value selector functions.
  * <p>The toDictionary method returns a Dictionary, a one-to-one dictionary that maps keys to values. If the source sequence contains multiple values with the same key, the result dictionary will only contain the latter value.
  * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key.
  * @param callable|null $valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value.
  * @return collections\Dictionary A Dictionary that contains values selected from the input sequence.
  */
 public function toDictionary($keySelector = null, $valueSelector = null)
 {
     $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$key);
     $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value);
     $dic = new c\Dictionary();
     foreach ($this as $k => $v) {
         $dic->offsetSet(call_user_func($keySelector, $v, $k), call_user_func($valueSelector, $v, $k));
     }
     return $dic;
 }