承接 iterator-tools/pipeline 相关项目开发

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

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

iterator-tools/pipeline

Composer 安装命令:

composer require iterator-tools/pipeline

包简介

Tools to work with iterators including lazy evaluation

README 文档

README

Build status

Library provides tools for working with iterators in a convenient way. Promotes functional style of programming when dealing with iterable collections.

Install using Composer:

composer require iterator-tools/pipeline

Example:

Allows defining iterators pipeline separately from actually consuming it. Allows processing large collections by avoiding loading all data into the memory at once - each key, value pair returned by source iterator is passed by multiple stages separately.

<?php

use IteratorTools\Source\Csv\CsvReader;
use IteratorTools\Source\Csv\CsvReaderOptions;
use function IteratorTools\Iterator\pipeline;
use function IteratorTools\Consumers\int_sum;

$options = CsvReaderOptions::defaults()->withDateColumn('created_at', 'Y-m-d H:i');

// First you need an iterable source from which you can create a stream
$csv = CsvReader::from('some-file.csv', $options)->readAssoc();

// Some helper object
$deadline = new DateTime('2022-03-01 00:00');

// Here we create a "pipeline" using source Iterator
$total = pipeline($csv)
    // First we tell that we want to filter all rows by date
    // (no iteration is happening at this moment)
    ->filter(function (array $row) use ($deadline) {
        return $row['created_at'] >= $deadline;
    })
    // Then we tell that after filtering we want mapping to integer values
    // (still, no iteration happens here)
    ->map(fn($row) => (int)$row['count'])
    // And here we want to consume all integers
    // and compute an integer sum
    // (here $csvReader is consumed; one row from file
    // at a time is filtered, mapped and then summed)
    // This line returns integer value.
    // result: 70
    ->consume(int_sum());

Example some-file.csv file for the code above:

id,count,created_at
1,30,"2022-01-01 12:00"
2,10,"2022-02-01 12:00"
3,50,"2022-03-01 12:00"
4,20,"2022-04-01 12:00"

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固