pepegar/streams-php 问题修复 & 功能扩展

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

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

pepegar/streams-php

Composer 安装命令:

composer require pepegar/streams-php

包简介

A port of the Streams library for Java8. Let's make PHP cooler.

README 文档

README

Build Status License SensioLabsInsight

Streams is a port of the Streams library for PHP. It makes working with collections super pleasant.

Installation

Just add the following to your composer.json file:

"pepegar/streams-php": "dev-master"

Usage

An example with the Yii ActiveRecord lib:

<?php

use Streams as S;

$collection = Car::model()->findAll(); // Returns an array of Car objects
$carStream = new S\Stream($collection);

$newCollection = $carStream
    ->filter(function( $car ) {
		return ($car->price > 36000); // return only expensive cars!
	})->map(function( $car ) {
		$car->setCo2EmissionTaxes(20); // Since is an expensive car, lets make the people who drive it more poor :D
		return $car;
	})->getElements();

Available functions

Even though this library is under active development, the currently available methods are:

###map(callable $callback) As in every functional programming language, map takes a function as argument and applies it to each element in the array, returning a new array with the results.

###filter(callable $callback) takes a function as argument and applies it to each element in the collection. It returns a new collection containing all elements where the callback returned true.

###allMatch(callable $predicate) returns wether all the elements in the stream match the given predicate

###anyMatch(callable $predicate) returns wether any the elements in the stream match the given predicate

###concat(Stream $a, Stream $b) Creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream.

###count() returns the count of elements in the stream

###distinct() returns a new stream consisting of the distinct elements of the stream

Hacking

Please, submit your Pull Requests, and make sure that the build passes.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固