Build the CSV object from a collection of models
https://csv.thephpleague.com/9.0/writer/

@param  Collection $items
@return Writer
497120
protected function makeCsv($items)
    {
        $csv = Writer::createFromFileObject(new SplTempFileObject());
        $csv->insertOne($this->getCsvHeaderNames($items));
        $items->each(function($item) use ($csv) {
            $row = $item->forExport();
            if (is_object($row) && method_exists($row, 'toArray')) {
                $row = $row->toArray();
            }
            $csv->insertOne($row);
        });
        return $csv;
    }
1163649
private static function writeItemsToResource(
        $resource,
        array $items
    ) {
        foreach ($items as $item) {
            fputcsv($resource, [
                $item->getId(),
                $item->getType(),
                json_encode($item->getMetadata()),
                json_encode($item->getIndexedMetadata()),
                json_encode($item->getSearchableMetadata()),
                json_encode($item->getExactMatchingMetadata()),
                json_encode($item->getSuggest()),
                json_encode(
                    ($item->getCoordinate() instanceof Coordinate)
                        ? $item->getCoordinate()->toArray()
                        : null
                ),
            ]);
        }
    }
690878
protected function setCartItems($items)
    {
        return (new Collection($items))->map(function ($item, $num) {
            return [
                'L_PAYMENTREQUEST_0_NAME'.$num => $item['name'],
                'L_PAYMENTREQUEST_0_AMT'.$num  => $item['price'],
                'L_PAYMENTREQUEST_0_QTY'.$num  => isset($item['qty']) ? $item['qty'] : 1,
            ];
        })->flatMap(function ($value) {
            return $value;
        });
    }
721318
protected function renderItems($items)
	{
		$script = '';
		foreach ($items as $key => $item)
		{
			if(is_array($item))
			{
				$script = $script."'$key':[";
				foreach ($item as $value)
					$script = $script."'$value',";
				$script = $script."],";
			} else
				$script = $script."'$key':'$item',";
		}
		return $script;
	}
678044
public CSV header(String... items) {
      this.header = (items == null ? null : Arrays.asList(items));
      if (header != null && header.size() > 0) {
         this.hasHeader = true;
      }
      return this;
   }
163009
private function doVolumeRepack(iterable $items): PackedBoxList
    {
        $packer = new Packer();
        $packer->setBoxes($this->boxes); // use the full set of boxes to allow smaller/larger for full efficiency
        $packer->setItems($items);

        return $packer->doVolumePacking();
    }
801644
public function setItems($items)
    {
        $this->items = ($items instanceof Collection) ? $items : Collection::make($items);

        return $this;
    }
278545
protected function makeTree(array &$items)
    {
        $result = [];
        $tops = [];

        /**
         * @var Entity $item
         */
        foreach ($items as $item) {
            $result[$item->getKey()] = $item;
        }

        foreach ($items as $item) {
            $parentId = $item->{$item->getParentIdColumn()};

            if (array_key_exists($parentId, $result)) {
                $result[$parentId]->appendRelation($item->getChildrenRelationIndex(), $item);
            } else {
                $tops[] = $item;
            }
        }

        return $tops;
    }
1293687
def csv_from_items(items, stream=None):
        
        items = iter(items)
        first = next(items)
        cls = first.__class__
        if stream is None:
            stream = sys.stdout
        fields = [f.name for f in attr.fields(cls)]
        writer = csv.DictWriter(stream, fieldnames=fields)
        writer.writeheader()
        writer.writerow(attr.asdict(first))
        writer.writerows((attr.asdict(x) for x in items))
652779
public function setItems(array $items)
    {
        $this->items = $items;
        $this->names = array_keys($items);

        return $this;
    }
1224924
public function zip($items): CollectionInterface
    {
        $items = array_map(function ($items) {
            if ($items instanceof IteratorAggregate) {
                return $items->getIterator();
            }

            if (is_array($items)) {
                return new ArrayIterator($items);
            }

            return $items;
        }, func_get_args());

        return $this->wrap(function (Iterator $data) use ($items) {
            foreach ($data as $key => $datum) {
                $result = [$datum];

                /** @var Iterator $item */
                foreach ($items as $item) {
                    $result[] = $item->current();
                    $item->next();
                }

                yield $key => $this::make($result);
            }
        });
    }
611468
public function updateMany(array $items)
    {
        $ids    = array_pluck($items, $this->model->getKeyName());
        $models = $this->model->find($ids);

        foreach ($models as $model) {
            $attributes = array_first($items, function ($i, $attributes) use ($model) {
                if (!array_key_exists($model->getKeyName(), $attributes)) {
                    return false;
                }

                return $attributes[$model->getKeyName()] == $model->getKey();
            });

            $this->validation()->validate('update', array_merge($attributes, [$model->getKeyName() => $model->getKey()]));

            $model->fill($attributes);
            $model->save();
        }

        return $models;
    }
420345
public static function sequence(...$items){
        $cmd = [];
        foreach ($items as $item) {
            $cmd[] = ($item instanceof static)?$item->getShellCommand():$item;
        }
        return new static(implode(' && ',$cmd));
    }
87956
protected function processItems(array $items)
    {
        $processedItems = [];

        foreach ($items as $entry) {
            $processedItems[] = ModelFactory::make($entry);
        }

        $this->items = new ModelCollection($processedItems);
    }
93119
public function append($items, bool $preserveKeys = true): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) use ($items, $preserveKeys) {
            $lists = [$data, self::make($items)];

            foreach ($lists as $list) {
                foreach ($list as $key => $item) {
                    if ($preserveKeys) {
                        yield $key => $item;
                    } else {
                        yield $item;
                    }
                }
            }
        });
    }
83894
public function add( ...$items )
	{
		foreach ( $items as &$item ) $item = (array)$item;
		$this->items = array_merge( $this->items , ...$items );
		return $this;
	}
151853
public function setItems($items)
    {
        if ($items && !$items instanceof ItemBag) {
            $items = new MulticardsItemBag($items);
        }

        return $this->setParameter('items', $items);
    }