Example #1
0
 /**
  * This method unsubscribes a listener.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the left operand
  * @param ITuple\Type $entry                                a tuple containing the key and listener
  * @return IHashMap\Type                                    the map
  */
 public static function unsubscribe(IHashMap\Type $xs, ITuple\Type $entry) : IHashMap\Type
 {
     $k = $entry->first();
     if ($xs->__hasKey($k)) {
         $ys = ILinkedList\Module::delete($xs->item($k), $entry->second());
         $zs = IHashMap\Module::putEntry($xs, ITuple\Type::box2($k, $ys));
         return $zs;
     }
     return $xs;
 }
Example #2
0
 /**
  * This method applies each item in this hash set to the subroutine function.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the hash map
  * @param callable $subroutine                              the subroutine function to be used
  * @return IHashMap\Type                                    the hash map
  */
 public static function map(IHashMap\Type $xs, callable $subroutine) : IHashMap\Type
 {
     $zs = IHashMap\Type::empty_();
     $xi = IHashMap\Module::iterator($xs);
     $i = IInt32\Type::zero();
     foreach ($xi as $k => $v) {
         $entry = ITuple\Type::box2($k, $v);
         $zs = IHashMap\Module::putEntry($zs, $subroutine($entry, $i));
         $i = IInt32\Module::increment($i);
     }
     return $zs;
 }