GithubHelp home page GithubHelp logo

Support generics about compiler HOT 2 CLOSED

xp-framework avatar xp-framework commented on May 19, 2024
Support generics

from compiler.

Comments (2)

thekid avatar thekid commented on May 19, 2024

Real-life example:

diff --git a/src/main/php/de/thekid/dialog/color/PriorityQueue.php b/src/main/php/de/thekid/dialog/color/PriorityQueue.php
index a683a76..6fcb295 100755
--- a/src/main/php/de/thekid/dialog/color/PriorityQueue.php
+++ b/src/main/php/de/thekid/dialog/color/PriorityQueue.php
@@ -1,12 +1,12 @@
 <?php namespace de\thekid\dialog\color;
 
 /** @test de.thekid.dialog.unittest.PriorityQueueTest */
-class PriorityQueue {
+class PriorityQueue<T> {
   private $elements= [];
   private $sorted= true;
   private $comparator= null;
 
-  public function comparing(function(mixed, mixed): int $comparator): self {
+  public function comparing(function(T, T): int $comparator): self {
     $this->comparator= $comparator;
     return $this;
   }
@@ -17,13 +17,13 @@ class PriorityQueue {
   }
 
   /** Pushes an element */
-  public function push($element): void {
+  public function push(T $element): void {
     $this->elements[]= $element;
     $this->sorted= false;
   }
 
   /** Pops an element */
-  public function pop() {
+  public function pop(): ?T {
     if (!$this->sorted) {
       $this->comparator ? usort($this->elements, $this->comparator) : sort($this->elements);
       $this->sorted= true;

Maybe as an addition xp-lang/xp-generics package?

from compiler.

thekid avatar thekid commented on May 19, 2024

Maybe as an addition xp-lang/xp-generics package?

Yes 😄 -> https://github.com/xp-lang/xp-generics/releases/tag/v0.4.0

from compiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.