Example #1
0
 /**
  * This method returns a string representing a sequence of substring delimited by the
  * specified string.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the delimiter
  * @param ISeq\Type $ys                                     a sequence of substrings
  * @return IString\Type                                     the string
  */
 public static function join(IString\Type $xs, ISeq\Type $ys)
 {
     $zs = array_map(function (IString\Type $y) : bool {
         return $y->unbox();
     }, $ys->unbox());
     return IString\Type::box(implode($xs->unbox(), $zs));
 }
Example #2
0
 /**
  * This method returns a formatted string using the specified sequence of objects.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the string to be formatted
  * @param ISeq\Type $ys                                     the objects to be incorporated
  * @return IString\Type                                     the newly formatted string
  */
 public static function format(IString\Type $xs, ISeq\Type $ys) : IString\Type
 {
     $buffer = $xs->unbox();
     $length = $ys->length();
     for ($i = IInt32\Type::zero(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) {
         $search = '{' . $i->__toString() . '}';
         $buffer = str_replace($search, $ys->item($i)->__toString(), $buffer);
     }
     return IString\Type::box($buffer);
 }
Example #3
0
 /**
  * This method returns the sum of all items in the list.
  *
  * @access public
  * @static
  * @param ISeq\Type $xs                                     the sequence to be processed
  * @return IDouble\Type                                     the result
  */
 public static function sum(ISeq\Type $xs) : IDouble\Type
 {
     return $xs->foldLeft(function (IDouble\Type $c, INumber\Type $x) {
         return IDouble\Module::add($c, $x->toDouble());
     }, IDouble\Type::zero());
 }