vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.67k stars 627 forks source link

Leverage Streams for Parallel Programming - E.g. Dataflow Programming / Functional Reactive Programming (FRP) / Communicating Sequential Processes (CSP) / Algorithmic skeleton (Parallelism Patterns) #231

Closed sirinath closed 7 years ago

sirinath commented 9 years ago

Libraries like http://www.paralleluniverse.co/quasar/, https://github.com/GPars/GPars, http://akka.io/ have this. It will be good to have similar features in this library also so you can have one cohesive library for similar needs.

danieldietrich commented 9 years ago

Thank you! Do you mean the feature of non-blocking streaming of data-chunks, which may be pulled from a source or may be also pushed from a source?

There has been some initial discussion in #79. At #186 I am tracking activities now.

sirinath commented 9 years ago

Something like this:

Val<Integer> a = new Val<>();
Var<Integer> x = new Var<>();
Var<Integer> y = new Var<>(() -> a.get() * x.get());
Var<Integer> z = new Var<>(() -> a.get() + x.get());
Var<Integer> r = new Var<>(() -> {
    int res = y.get() + z.get();
    System.out.println("res: " + res);
    return res;
});

Fiber<?> f = new Fiber<Void>(() -> {
    for (int i = 0; i < 200; i++) {
        x.set(i);
        Strand.sleep(100);
    }
}).start();

Strand.sleep(2000);
a.set(3); // this will trigger everything
f.join();

(Sourced from: http://docs.paralleluniverse.co/quasar/)

Also see documentation of: https://github.com/lihaoyi/scala.rx

danieldietrich commented 9 years ago

Without knowing how the classes are implemented this looks like some sophisticated implementation of the observer pattern with the addition of thread synchronization.

What I want is some few, strongly typed, composable building blocks. I haven't yet investigated what types of async abstractions are necessary to cover this whole topic with the minimum amount of types.

As said, without having deep-dived into that topic, the following dualities come to my mind:

A good starting point is the reactive-streams project. Resources:

Also non-functional aspects have to be covered, like

sirinath commented 9 years ago

I guess GPars is the most complete implementation. Perhaps you can look under the hood for what is happening.

sirinath commented 9 years ago

In the JS world this is a very interesting implementation: http://noflojs.org/

danieldietrich commented 7 years ago

out of scope for Javaslang