承接 assegaiphp/collections 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

assegaiphp/collections

最新稳定版本:0.9.0

Composer 安装命令:

composer require assegaiphp/collections

包简介

The assegaiphp/collections package is a powerful tool for creating and managing groups of related objects in your AssegaiPHP projects. With this library, you can easily organize and manipulate data in a variety of ways, such as arrays, lists, sets, and maps. The package offers a wide range of method

README 文档

README

Assegai Logo

Latest release Tests PHP 8.4+ License Status active

A progressive PHP framework for building effecient and scalable server-side applications.

AssegaiPHP Collections

A powerful and easy-to-use library for creating and managing collections of related objects in AssegaiPHP. This library provides a simple and intuitive interface for working with arrays of objects, making it easy to perform common operations such as filtering, mapping, and reducing.

Contribution workflow

For commit and pull request conventions in this repo, see:

Installation

You can install the library using composer by running the following command:

composer require assegaiphp/collections

Usage

To create a new collection, you can use the Assegai\Collections\Collection class. This class provides a simple and intuitive interface for working with arrays of objects, making it easy to perform common operations such as filtering, mapping, and reducing.

Here's an example of how to create a new collection and add some items to it:

use Assegai\Collections\Collection;

$collection = new Collection();
$collection->add(1);
$collection->add(2);
$collection->add(3);

Collections are traversable, so you can iterate over them directly with foreach:

use Assegai\Collections\ItemList;

$list = new ItemList('string', ['foo', 'bar', 'baz']);

foreach ($list as $index => $item) {
    echo "{$index}: {$item}\n";
}

ItemList also supports array-style access for indexed reads and writes:

$list = new ItemList('string', ['foo', 'bar']);

echo $list[0]; // foo

$list[1] = 'baz';
$list[] = 'tail';

unset($list[0]);

Once you have a collection, you can use the various methods provided by the class to manipulate the items in the collection. For example, you can use the filter method to filter the items in the collection based on a certain condition:

$filteredCollection = $collection->filter(function($item) {
    return $item > 1;
});

The map method can be used to transform the items in the collection:

$mappedCollection = $collection->map(function($item) {
    return $item * 2;
});

You can also use the reduce method to reduce the collection to a single value:

$sum = $collection->reduce(function($carry, $item) {
    return $carry + $item;
}, 0);

API

The API of the Assegai\Collections\Collection class is designed to be simple and intuitive. It provides the following methods:

  • add(mixed $item): Add an item to the collection
  • remove(mixed $item): Remove an item from the collection
  • filter(callable $callback): Filter the items in collection based on a callback function.

统计信息

  • 总下载量: 436
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固