承接 capci/stream 相关项目开发

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

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

capci/stream

Composer 安装命令:

composer require capci/stream

包简介

Java-like Stream API library for PHP

关键字:

README 文档

README

Build Status

Java-like Stream API library for PHP.

Intermediate operations are not evaluated until terminal operation is invoked (lazy evaluation).

Requires PHP 7.2 or newer.

Usage

Basic usage.

Stream::of("a", "b", "c", "d", "e", "x")->filter(function ($value) {
    return $value !== "x";
})->map(function($value) {
    return strtoupper($value);
})->forEach(function ($value) {
    echo $value . ", ";
});
// A, B, C, D, E,

Generate Stream

  • from values.
$stream = Stream::of("a", "b", "c");
  • from array or Traversable.
$stream = Stream::ofIterable([
    "a",
    "b",
    "c",
]);
$stream = Stream::ofIterable(new DirectoryIterator("."));
  • from generator function.
$stream = Stream::ofGenerator(function () {
    yield "a";
    yield "b";
    yield "c";
});
  • and others

empty, concat.

Intermediate operation

  • filter
$stream = Stream::ofIterable(range(0, 10));
$stream = $stream->filter(function ($value) {
    return $value > 5;
});
// 6 7 8 9 10
  • map
$stream = Stream::ofIterable(range(0, 5));
$stream = $stream->map(function ($value) {
    return $value * 2;
});
// 0 2 4 6 8 10
  • sorted
$stream = Stream::ofIterable(range(0, 5));
$stream = $stream->sorted(function ($value1, $value2) {
    return $value2 - $value1;
});
// 5 4 3 2 1 0
  • and others

flatMap, skip, skipWhile, limit, limitWhile, distinct, peek.

Terminal operation

  • forEach
$stream = Stream::ofIterable(range(0, 5));
$stream->forEach(function ($value) {
    echo $value . ", ";
});
// 0, 1, 2, 3, 4, 5,
  • toArray
$stream = Stream::ofIterable(range(0, 5));
$array = $stream->toArray();
// [0, 1, 2, 3, 4, 5]
  • reduce
$stream = Stream::ofIterable(range(0, 5));
$sum = $stream->reduce(0, function ($accum, $value) {
    return $accum + $value;
});
// 15
  • and others

count, allMatch, anyMatch, nonMatch, findFirstOrDefault, findLastOrDefault, maxOrDefault, minOrDefault.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固