当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::reduce方法代码示例

本文整理汇总了PHP中Illuminate\Support\Collection::reduce方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::reduce方法的具体用法?PHP Collection::reduce怎么用?PHP Collection::reduce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Collection的用法示例。


在下文中一共展示了Collection::reduce方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: resolve

 /**
  * Determines a winner from the list of buzzes accumulated.
  *
  * Note: This method is destructive, and will clear the list of buzzes on completion.
  * @return BuzzerResolution
  */
 public function resolve()
 {
     if ($this->isEmpty()) {
         return BuzzerResolution::createFailure();
     }
     /** @var BuzzReceivedEvent $winner */
     $winner = $this->buzzes->reduce(function (BuzzReceivedEvent $carry, BuzzReceivedEvent $event) {
         if ($event->getDifference() < $carry->getDifference()) {
             return $event;
         }
         return $carry;
     }, $this->buzzes->first());
     $resolution = BuzzerResolution::createSuccess($winner->getContestant(), $winner->getDifference());
     $this->buzzes = new Collection();
     return $resolution;
 }
开发者ID:mattsches,项目名称:Jeopardy,代码行数:22,代码来源:Resolver.php

示例2: createActivities

 protected function createActivities(Collection $schedulesByAuditorium)
 {
     $activities = $schedulesByAuditorium->reduce(function (Collection $allActivities, $arrayAuditoriumSchedules) {
         $auditoriumSchedules = Collection::make($arrayAuditoriumSchedules);
         // List of schedules of a auditorium grouped by films.
         $schedulesByFilm = $auditoriumSchedules->groupBy(function ($item) {
             return $item->exhibition->exhibition_film->film->id;
         });
         $activities = $this->activityFactory->collection($schedulesByFilm);
         // merge return a new Collection
         return $allActivities->merge($activities);
     }, Collection::make([]));
     return $activities;
 }
开发者ID:filmoteca,项目名称:filmoteca,代码行数:14,代码来源:ActivitiesRepository.php

示例3: breakIntoWidgets

 public static function breakIntoWidgets($widgetDom)
 {
     $widgets = [];
     $previous_was_paragraph = false;
     $current_paragraph_string = "";
     foreach ($widgetDom->find('*') as $index => $node) {
         if (self::checkIfValidParagraph($node->outertext)) {
             $new_paragraph = str_replace("<p>&nbsp;</p>", "", $node->outertext);
             $current_paragraph_string .= $new_paragraph;
         } else {
             if (!empty($current_paragraph_string)) {
                 $paragraphDom = HtmlDomParser::str_get_html($current_paragraph_string);
                 array_push($widgets, Paragraph::getFromWidgetDom($paragraphDom));
                 $current_paragraph_string = "";
             }
             if ($node->tag == 'h2') {
                 array_push($widgets, Heading::getFromWidgetDom($node));
                 continue;
             }
             if ($embedData = Embed::getFromWidgetDom($node)) {
                 array_push($widgets, $embedData);
                 continue;
             } else {
                 if (self::checkStringAgainstBlacklist($node->outertext)) {
                     $html = new stdClass();
                     $html->type = 'html';
                     $html->html = $node->outertext;
                     array_push($widgets, $html);
                 }
             }
         }
     }
     if (!empty($current_paragraph_string)) {
         $paragraphDom = HtmlDomParser::str_get_html($current_paragraph_string);
         array_push($widgets, Paragraph::getFromWidgetDom($paragraphDom));
     }
     $widgetCollection = new Collection($widgets);
     // HTML Merge step
     foreach ($widgets as $index => $widget) {
         if ($index != 0) {
             $prev = $widgets[$index - 1];
             if ($prev->type == 'html' && $widget->type == 'html') {
                 $widget->html = $prev->html . $widget->html;
                 unset($widgets[$index - 1]);
             }
         }
     }
     $widgets = array_values($widgets);
     $htmlCheck = $widgetCollection->reduce(function ($carry, $item) {
         return $item->type == 'html';
     });
     if ($htmlCheck) {
         $widgets = array($widgetCollection->reduce(function ($carry, $item) {
             if (!$carry) {
                 $carry = new stdClass();
                 $carry->html = '';
             }
             $carry->type = $item->type;
             $carry->html .= $item->html;
             return $carry;
         }));
     }
     return count($widgets) ? $widgets : false;
 }
开发者ID:shortlist-digital,项目名称:agreable-catfish-importer-plugin,代码行数:64,代码来源:Html.php

示例4: testReduce

 public function testReduce()
 {
     $data = new Collection([1, 2, 3]);
     $this->assertEquals(6, $data->reduce(function ($carry, $element) {
         return $carry += $element;
     }));
 }
开发者ID:sa7bi,项目名称:euro16,代码行数:7,代码来源:SupportCollectionTest.php

示例5: originalPrice

 /**
  * What would the offer components have cost without the offer?
  *
  * @throws \InvalidArgumentException
  *
  * @return Money
  */
 public function originalPrice() : Money
 {
     return $this->components->reduce(function (Money $price, OfferComponent $component) {
         return $price->add($component->product()->price()->asMoney());
     }, Money::fromInt(0));
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:13,代码来源:PotentialOffer.php


注:本文中的Illuminate\Support\Collection::reduce方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。