定制 xp-lang/xp-generics 二次开发

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

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

xp-lang/xp-generics

最新稳定版本:v2.1.0

Composer 安装命令:

composer require xp-lang/xp-generics

包简介

XP generics for PHP

README 文档

README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

Plugin for the XP Compiler which adds support for XP generics.

Example

// Declaration
namespace com\example;

class PriorityQueue<E> {
  private $elements;
  private $comparator= null;
  private $sorted= true;

  public function __construct(E... $elements) {
    $this->elements= $elements;
  }

  public function comparing(?function(E, E): int $comparator): self {
    $this->comparator= $comparator;
    return $this;
  }

  public function push(E $element): void {
    $this->elements[]= $element;
    $this->sorted= false;
  }

  public function pop(): ?E {
    if (!$this->sorted) {
      $this->comparator ? usort($this->elements, $this->comparator) : sort($this->elements);
      $this->sorted= true;
    }
    return array_pop($this->elements);
  }
}


// Usage
$q= new PriorityQueue<string>();
$q->push('Test');

$q->push(123); // lang.IllegalArgumentException

Installation

After installing the XP Compiler into your project, also include this plugin.

$ composer require xp-framework/compiler
# ...

$ composer require xp-lang/xp-generics
# ...

No further action is required.

See also

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-11-06