示例#1
0
 /**
  * The method intersperses the specified object between each item in the string.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the left operand
  * @param Core\Type $y                                      the object to be interspersed
  * @return IString\Type                                     the string
  * @throws Throwable\InvalidArgument\Exception              indicates an invalid argument
  */
 public static function intersperse(IString\Type $xs, Core\Type $y) : IString\Type
 {
     $buffer = '';
     $length = $xs->length();
     if ($length->unbox() > 0) {
         $buffer .= IString\Module::item($xs, IInt32\Type::zero())->unbox();
         for ($i = IInt32\Type::one(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) {
             $buffer .= $y->__toString();
             $buffer .= $xs->__item($i);
         }
     }
     return IString\Type::box($buffer);
 }