/** * 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); }
/** * 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); }
/** * 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); }
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)); }