承接 konfirm/collection 相关项目开发

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

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

konfirm/collection

Composer 安装命令:

composer require konfirm/collection

包简介

Uniform collection (array-like) operations

README 文档

README

Simple implementation of common array operations with a unified argument list for filter, map and reduce similar to the ECMA/Javascript implementations

Example use

Unique

Remove all duplicate entries

<?php

use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c', 'b', 'a');
$unique = $provider->unique();
//  'a', 'b', 'c'

Intersect

Create a new Provider containing the elements which are present in two Providers

<?php

use Konfirm\Collection\Provider;

$first = new Provider('a', 'b', 'c', 'b', 'a');
$second = new Provider('foo', 'bar', 'c', 'b');

$common = $first->intersect($second);
//  'b', 'c', 'b';

Filter

<?php

use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c', 'b', 'a');
$filtered = $provider->filter(function($value, $index /*, $provider*/) {
	return $value !== 'a' && $index % 2 === 0;
});
// 'c'

Map

<?php

use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c', 'b', 'a');
$mapped = $provider->map(function($value /*, $index, $provider*/) {
	return sprintf('*%s*');
});
// '*a*', '*b*', '*c*', '*b*', '*a*'   

Reduce

Support for both the uninitialized (using the first item from the Provider) and the initialized (initial value is provided) reduce

uninitialized

<?php

use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c');
$reduce = $provider->map(function($carry, $value, $index) {
	return $carry + $value;
});
// 'abc'   

initialized

<?php

use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c');
$reduce = $provider->map(function($carry, $value, $index) {
	return $carry + $value;
}, 'my result: ');
// 'my result: abc'   

Comparing objects

If there is need for comparing objects based on (a subset of) properties, one can implement the Konfirm\Collection\Comparable-interface, which specifies the getComparison method which is used (should both objects implement the interface) if (and only if) both objects are not identical (===)

Features

  • PSR-4 autoloading compliant structure
  • Full code coverage with PHPUnit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固