Skip to content

josejuan/lombok

 
 

Repository files navigation

This is a dirty fork to play with a proof of concept about do notation for java.

The unique files added (no changes was maded to lombok itself) are:

* src/core/lombok/BindTo.java
* src/core/lombok/bind.java
* src/core/lombok/javac/handlers/HandleBind.java

Quick explanation:

Let M some class with a monadic operation (e.g. flatMap for Optional o Stream):

    M<B> flatMap(Function<A, M<B>> k) {...

Then, you can annotate one getter of M as:

    @BindTo(method = "flatMap")
    T get() {
        throw new IllegalStateException("this method should be erased at compiled (lombok) time");
    }

Now the users can use your monad without lambda and dot chaining (e.g. `x.flatMap(y -> y.flatMap(...`),
they can use @bind to bind the result of each monadic application, e.g.:

    private static Either<String, Double> solveQuadratic(final String equation) {
        @bind String[] mx = parseRegex(MY_REGEX, equation).get();
        @bind Double a = parseDouble(mx[1]).get();
        @bind Double b = parseDouble(mx[2]).get();
        @bind Double c = parseDouble(mx[3]).get();
        return solveQuadratic(a, b, c).toEither("I don't know the imaginary numbers!");
    }

The bind expansion work from:

  @bind T x = m.k();
  BLOCK;
  return w;

where

  - T is the type into the monad.
  - x is the variable definition.
  - m is some monad expression.
  - k is the `BindTo` getter.
  - BLOCK is any internal code.
  - w is the monadic result.

This will be expanded to:

  return m.k'((T x) -> {
    BLOCK;
    return w;
  });

where

  - k' is the `BindTo` method of k

========================

Project Lombok makes java a spicier language by adding 'handlers' that know how to build and compile simple, boilerplate-free, not-quite-java code.
See LICENSE for the Project Lombok license.


To start, run:

ant -projecthelp

HINT: If you'd like to develop lombok in eclipse, run 'ant eclipse' first. It creates the necessary project infrastructure and downloads dependencies. Note that, in order to run "LombokizedEclipse.launch", you need to have "Eclipse SDK" installed.

For a list of all authors, see the AUTHORS file.

Project Lombok was started by:

Reinier Zwitserloot
twitter: @surial
home: https://zwitserloot.com/

Roel Spilker

About

Very spicy additions to the Java programming language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 93.2%
  • HTML 5.9%
  • JavaScript 0.5%
  • CSS 0.1%
  • Dockerfile 0.1%
  • Shell 0.1%
  • Other 0.1%