vert-x3 / vertx-rx

Reactive Extensions for Vert.x
Apache License 2.0
147 stars 72 forks source link

Extension methods #152

Open vietj opened 6 years ago

vietj commented 6 years ago

Support extension methods in a similar fashion than Groovy or Kotlin provide.

package foo.bar;

@VertxGen
public interface Foo {
  // Some methods
}

If on the classpath we have:

public interface FooHelper /* Convention */ {
   public static String bar(Foo foo, String s) {
      return foo.toString + s;
   }
}

Then the generated Foo rx wrapper can be augmented with this method:

public class Foo {
   private foo.bar.Foo delegate;
   public String bar(String s) {
      return FooHelper.bar(delegate, s);
   }
}
tsegismont commented 6 years ago

@vietj you piqued my curiosity :) Can you elaborate on a concrete use case you had in mind?

vietj commented 6 years ago

retrofit some existing helper method, for instance:

  public static Scheduler scheduler(io.vertx.core.Vertx vertx) {
    return new ContextScheduler(vertx, false);
  }

we get then a scheduler() method on io.vertx.reactivex.core.Vertx, etc...

vietj commented 6 years ago

so the goal is to provide a more oo-ish experience when using vertx-rx

tsegismont commented 6 years ago

Thanks for the details. Indeed, great idea :)