hguenot/phpstream 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hguenot/phpstream

最新稳定版本:V3.0.0

Composer 安装命令:

composer require hguenot/phpstream

包简介

PHPStream claims to be a partial PHP port of the Java Stream API.

README 文档

README

PHP Stream is a basic port of new Java Stream API in PHP.

This library could be used to filter, convert or reduce any array.

Continuous integration

Build Status Code coverage GitHub last version Packagist last version Packagist downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist hguenot/phpstream "*"

or add

"hguenot/phpstream": "*"

to the require section of your composer.json file.

Usage

  • Here is a basic usage of this library.
// Create a simple array of data
$array = [ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];

// Creates a Stream based on the previous array
$stream = new \phpstream\Stream($array);

// Compute the opposite value of each value
$stream = $stream->map(function($value){
    return intval($value) * (-1);
});

// Get only odd values
$stream = $stream->filter(function($value){
    return (intval($value) % 2) == 0;
});

// Collects data into an array
$new_array = $stream->collect(new \phpstream\collectors\ListCollector());

// Computes sum of all elements
$sum = $stream->reduce(function($a, $b){
    return intval($a) + intval($b);
}, 0);
  • All stream operations can be chained :
$sum = \phpstream\Stream::of($array)
    ->map(function($value){
        return intval($value) * (-1);
    })
    ->filter(function($value){
        return (intval($value) % 2) == 0;
    })
    ->reduce(function($a, $b){
        return intval($a) + intval($b);
    }, 0);

You can find more examples on PHPUnit test.

统计信息

  • 总下载量: 602
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固