Exemple #1
0
 /**
  * This method returns an option containing the value paired with the lookup key x.
  *
  * @access public
  * @static
  * @param IArrayList\Type $xss                              the left operand
  * @param Core\Equality\Type $x                             the key being looked up
  * @return IOption\Type                                     an option containing the associated
  *                                                          value
  * @throws Throwable\UnexpectedValue\Exception              indicates that the list is not
  *                                                          associative
  */
 public static function lookup(IArrayList\Type $xss, Core\Equality\Type $x) : IOption\Type
 {
     $xssi = IArrayList\Module::iterator($xss);
     foreach ($xssi as $i => $xs) {
         if (!ITuple\Module::isPair($xs)->unbox()) {
             throw new Throwable\UnexpectedValue\Exception('Unable to process tuple. Expected a length of "2", but got a length of ":length".', array(':length' => $xs->__length()));
         }
         if ($x->__eq(ITuple\Module::first($xs))) {
             return IOption\Type::some(ITuple\Module::second($xs));
         }
     }
     return IOption\Type::none();
 }
Exemple #2
0
 /**
  * This method returns an option containing the value paired with the lookup key x.
  *
  * @access public
  * @static
  * @param ILinkedList\Type $xss                             the left operand
  * @param Core\Equality\Type $x                             the key being looked up
  * @return IOption\Type                                     an option containing the associated
  *                                                          value
  * @throws Throwable\UnexpectedValue\Exception              indicates that the list is not
  *                                                          associative
  */
 public static function lookup(ILinkedList\Type $xss, Core\Equality\Type $x) : IOption\Type
 {
     if ($xss->__isEmpty()) {
         return IOption\Type::none();
     }
     $xs = $xss->head();
     if (!ITuple\Module::isPair($xs)->unbox()) {
         throw new Throwable\UnexpectedValue\Exception('Unable to process tuple. Expected a length of "2", but got a length of ":length".', array(':length' => $xs->__length()));
     }
     if ($x->__eq(ITuple\Module::first($xs))) {
         return IOption\Type::some(ITuple\Module::second($xs));
     }
     return ILinkedList\Module::lookup($xss->tail(), $x);
 }