nicofff/lazy-iter 问题修复 & 功能扩展

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

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

nicofff/lazy-iter

Composer 安装命令:

composer require nicofff/lazy-iter

包简介

Lazy array function chains inspired in Rust

README 文档

README

Lazy array function chains inspired by Rust

Design goals

  1. Be lazy (as in Lazily evaluated)
  2. Have a similar interface to Rust's Iterator
  3. Leverage static code analyzers to validate type correctness

Install

composer require nicofff/lazy-iter

PHP 7.4 required

Examples

<?php
require_once __DIR__ . '/vendor/autoload.php';
use LazyIter\LazyIter;
use LazyIter\Helpers\Generators\Range;

// Calculate the sum of all the squared numbers below a million
$sum_squares_under_a_million = 
    (new LazyIter(Range::rangeFrom(1))) // Start with an iterator over all positive numbers
	->map(fn($n) => pow($n,2) ) // Square each one of them
	->take_while(fn($n) => $n < 1_000_000 ) // Stop once we reach a million
	->sum(); // sum them

echo $sum_squares_under_a_million;

Project status

Methods implemented (based on Rust's Iterator Trait)

  • all
  • any
  • chain
  • collect
  • count
  • cycle
  • filter
  • fold
  • for_each
  • last
  • map
  • nth
  • skip
  • sum
  • take
  • take_while

Type Enforcement

Currently using PHPStan for type validation. Check type_tests for a list of things it caches for each method

Example

LazyIter::fromArray([2,4,6,8])
->for_each(function(string $n): void{
	echo $n;
});

Raises:

Parameter #1 $callable of method                                      
         LazyIter\LazyIter<int,int>::for_each() expects callable(int): mixed,  
         Closure(string): void given. 

Accepting contributions to support Phan and Psalm

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固