/** * This method returns the option as a linked list. * * @access public * @static * @param IOption\Type $xs the operand * @return ILinkedList\Type the option as a linked list */ public static function toLinkedList(IOption\Type $xs) : ILinkedList\Type { return $xs->__isDefined() ? ILinkedList\Type::cons($xs->item()) : ILinkedList\Type::nil(); }
/** * This method returns the collection as a linked list. * * @access public * @static * @param IString\Type $xs the operand * @return ILinkedList\Type the collection as a linked list */ public static function toLinkedList(IString\Type $xs) : ILinkedList\Type { $length = $xs->length(); $zs = ILinkedList\Type::nil(); for ($i = IInt32\Module::decrement($length); IInt32\Module::ge($i, IInt32\Type::zero())->unbox(); $i = IInt32\Module::decrement($i)) { $zs = ILinkedList\Type::cons($xs->item($i), $zs); } return $zs; }
/** * This method creates a list of "n" length with every item set to the given object. * * @access public * @static * @param Core\Type $x the object to be replicated * @param IInt32\Type $n the number of times to replicate * @return ILinkedList\Type the collection */ public static function replicate(Core\Type $x, IInt32\Type $n) : ILinkedList\Type { if ($n->unbox() <= 0) { return ILinkedList\Type::nil(); } return ILinkedList\Type::cons($x, ILinkedList\Type::replicate($x, IInt32\Module::decrement($n))); }
/** * This method returns the hash map as a linked list. * * @access public * @static * @param IHashMap\Type $xs the hash map * @return ILinkedList\Type the hash map as a linked list */ public static function toLinkedList(IHashMap\Type $xs) : ILinkedList\Type { $zs = ILinkedList\Type::nil(); $xi = IHashMap\Module::iterator($xs); foreach ($xi as $x) { $zs = ILinkedList\Type::cons($x, $zs); } return $zs; }
/** * This method returns the either as a linked list. * * @access public * @final * @return ILinkedList\Type the either as a linked list */ public final function toLinkedList() : ILinkedList\Type { return $this->either->__isLeft() ? ILinkedList\Type::cons($this->either->item()) : ILinkedList\Type::nil(); }
/** * This method returns a new list of tuple pairings. * * @access public * @static * @param ILinkedList\Type $xs the left operand * @param ILinkedList\Type $ys the right operand * @return ILinkedList\Type a new list of tuple pairings */ public static function zip(ILinkedList\Type $xs, ILinkedList\Type $ys) : ILinkedList\Type { $start = ILinkedList\Type::nil(); $tail = null; for ($as = $xs, $bs = $ys; !$as->__isEmpty() && !$bs->__isEmpty(); $as = $as->tail(), $bs = $bs->tail()) { $tuple = ITuple\Type::box2($as->head(), $bs->head()); $cons = ILinkedList\Type::cons($tuple); if ($tail !== null) { $tail->tail = $cons; } else { $start = $cons; } $tail = $cons; } return $start; }