Services.Op

An example demonstrating the use of the Op functional interface and related methods. Note the last two execute calls act as operations, whereas the first two execute calls return an integer value from the method called.

package io.opensignals.services.samples;

import io.opensignals.services.Services;
import io.opensignals.services.Services.Fn;
import io.opensignals.services.Services.Op;
import io.opensignals.services.Services.Service;

final class Ops {

  public static void main (
    final String[] args
  ) throws Throwable {

    final Service service =
      Services
        .context ()
        .service (
          Services.name (
            "service.one"
          )
        );

    assert
      1 ==
        Services
          .execute (
            service,
            () ->
              doWork ()
          );

    assert
      1 ==
        Services
          .execute (
            service,
            (Fn< Integer, ? >)
              Ops::doWork
          );

    Services
      .execute (
        service,
        Op.of (
          Ops::doWork
        )
      );

    Services
      .execute (
        service,
        Op.from (
          Ops::doWork
        )
      );

  }

  private static int doWork () {

    return 1;

  }

  static int doWork (
    final int units
  ) {

    return
      units;

  }

}