예제 #1
0
 /**
  * Turn request examples to a RAML message body.
  *
  * @param Request[] $requests
  *
  * @return RamlMessageBody
  */
 protected function requestsToBody($requests)
 {
     return Std::foldl(function (RamlMessageBody $messageBody, Request $request) {
         return $messageBody->addType($request->headers->get('content-type'), (new RamlBody())->setExample($request->getContent()));
     }, new RamlMessageBody(), $requests);
 }
예제 #2
0
파일: Rope.php 프로젝트: chromabits/nucleus
 /**
  * Concatenate with other strings.
  *
  * @param array<string|Rope> ...$others
  *
  * @return Rope
  */
 public function concat(...$others)
 {
     return static::of(Std::foldl(function ($carry, $part) {
         return $carry . (string) $part;
     }, $this->contents, $others), $this->encoding);
 }
예제 #3
0
 /**
  * Run the input through the pipeline.
  *
  * @param array $input
  *
  * @return array
  */
 public function run(array $input)
 {
     return Std::foldl(function ($current, TransformInterface $input) {
         return $input->run($current);
     }, $input, $this->transforms);
 }
예제 #4
0
 public function testFoldl()
 {
     $input = ArrayList::of([1, 2, 3, 4, 5]);
     $inputChars = ArrayList::of(['h', 'e', 'l', 'l', 'o']);
     $sum = function ($x, $y) {
         return $x + $y;
     };
     $concat = function ($x, $y) {
         return $x . $y;
     };
     $this->assertEquals(10 + 1 + 2 + 3 + 4 + 5, Std::foldl($sum, 10, $input));
     $this->assertEquals('---hello', Std::foldl($concat, '---', $inputChars));
 }