定制 bertptrs/phpstreams 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bertptrs/phpstreams

最新稳定版本:v0.1.0

Composer 安装命令:

composer require bertptrs/phpstreams

包简介

A streams library for PHP based on the Java 8 Streams API.

README 文档

README

Latest Stable Version Total Downloads License Build Status

A partial implementation of the Java 8 Streams API in PHP. PHPStreams can use your generators, your arrays and really anything that is Iterable and convert modify it like you're used to using Java Streams!

Using streams and generators, you can easily sort through large amounts of data without having to have it all in memory or in scope. Streams also make it easier to structure your code, by (more or less) enforcing single resposibility.

The library is compatible with PHP 5.5.9 and up.

Installation

PHPStreams can be installed using Composer. Just run composer require bertptrs/phpstreams in your project root!

Usage

Using streams is easy. Say, we want the first 7 odd numbers in the Fibonacci sequence. To do this using Streams, we do the following:

// Define a generator for Fibonacci numbers
function fibonacci()
{
    yield 0;
    yield 1;

    $prev = 0;
    $cur = 1;

    while (true) {
        yield ($new = $cur + $prev);
        $prev = $cur;
        $cur = $new;
    }
};

// Define a predicate that checks for odd numbers
$isOdd = function($num) {
    return $num % 2 == 1;
};

// Create our stream.
$stream = new phpstreams\Stream(fibonacci());

// Finally, use these to create our result.
$oddFibo = $stream->filter($isOdd)  // Keep only the odd numbers
    ->limit(8)                      // Limit our results
    ->toArray(false);               // Convert to array, discarding keys

Documentation

Documentation is mostly done using PHPDoc. I do intend to write actual documtation if there is any interest.

Contributing

I welcome contributions and pull requests. Please note that I do follow PSR-2 (and PSR-4 for autoloading). Also, please submit unit tests with your work.

GrumPHP enforces at least part of the coding standard, but do make an effort to structure your contributions nicely.

统计信息

  • 总下载量: 3.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 88
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 88
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固