Need help with cyclops-integration?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

aol
443 Stars 49 Forks MIT License 1.3K Commits 27 Opened issues

Description

Home of the cyclops integration modules : support for Scala, Clojure, RxJava (1+2), Reactor, FunctionalJava, Guava, Dexx & Vavr

Services available

!
?

Need anything else?

Contributors list

No Data

Integration modules home

screen shot 2016-02-22 at 8 44 42 pm

Documentation

Latest Articles

A common API across the functional landscape

cyclops provides a common set of APIs across the major functional libraries for Java. It does this via :

  1. A common abstraction layer (AnyM short for AnyMonad)
  2. Companion classes (Optionals, Streams, CompletableFutures, Options, Eithers, Lists, Trys etc) that provide common functionality such as For Comprehensions and Higher Kinded Haskell like type classes
  3. Provided conversion classes between types via FromXXX and ToXXX classes
  4. Allows collection types from all major functional libraries to be substituted behind cyclops-react lazy & reactive collection APIs

AnyM : a type safe abstraction across Any Monadic type in Java.

Define ultra-generic code that can be used by types across Vavr, Reactor, cyclops-react, Guava, JDK, Functional Java, RxJava.

public > AnyMSeq sumAdjacent(AnyMSeq sequence){
     return sequence.sliding(1)
                    .map(t->t.sum(i->i).get())
}

Use them with Vavr

import static cyclops.monads.VavrWitness.list;
import cyclops.companion.vavr.Lists;


AnyMSeq vavrList = Lists.anyM(List.range(0, 10)); AnyMSeq summedVavr = sumAdjacent(vavrList); List backToVavr = VavrWitness.list(summedVavr);

Or RxJava

import static cyclops.monads.Rx2Witness.observable;
import cyclops.companion.rx.Observables;

AnyMSeq rxObservable = Observables.anyM(Observable.range(0, 10)); AnyMSeq summedRx = sumAdjacent(rxObservable); Observable backToRx = RxWitness.observable(summedRx);

Common functionality in Companion classes

For comprehensions

import static cyclops.companion.vavr.Trys.*;


Try result = Trys.forEach4(grind("arabica beans"), ground -> heatWater(new Water(25)), (ground, water) -> brew(ground, water), (ground, water ,espresso) -> frothMilk("milk"), (ground , water ,espresso , foam) -> combine(espresso, foam));

System.out.println(result.get());

Try grind(String beans) { return Try.of(() -> "ground coffee of " + beans); }

Try heatWater(Water water) { return Try.of(() -> water.withTemperature(85)); }

Try frothMilk(String milk) { return Try.of(() -> "frothed " + milk); }

Try brew(String coffee, Water heatedWater) { return Try.of(() -> "espresso"); }

String combine(String espresso, String frothedMilk) { return "cappuccino"; }

import static cyclops.companion.reactor.Fluxs.*;

Flux result = Fluxs.forEach(Flux.just(10, 20), a -> Flux. just(a + 10), (a, b) -> a + b); result.collectList() .block(), //List[30, 50];

Lazy and Reactive Collection APIs

cyclops & cyclops-react allow collection types from all major functional libraries to be used behind fast lazy & reactive collection apis.

What do we mean by fast lazy & reactive APIs

Most Collection APIs provided by the major functional libraries are eager. That means when a map transformation is invoked on a Functional Java or Vavr List it is executed immediately. Performing multiple chained operations often results in the the collection being processed (traversed) multiple different times. With cyclops map and other functional operations become lazy, and the your chain of commands are only executed when data within the collection is exected for the first time. This allows cyclops to process the entire chain of operations in a single traversal of the data. The resultant transformed collection is then stored in the underlying structure of your favourite functional collection API.

The Performance benefit

Leveraging cyclops can significantly improve the execution times of operations on collections.

The code for this performance testing speeding up the execution of functional operations on Javaslang Vectors is available here cyclops-speed-up

Reactive APIs

cyclops also allows data to be pushed asynchronously into collection types from the major functional libraries. For example to asynchronously populate a JavaSlang / Vavr Vector we can write

VectorX asyncPopulated = JavaSlangPersistentList.fromStream(Spouts.publishOn(ReactiveSeq.of(1,2,3),
                Executors.newFixedThreadPool(1));

Type safe, higher kinded typeclassess

E.g. Using a functor and applicative type classes on FunctionalJava Lists (Higher Kinded encoding via ListKind type)

import static com.oath.cyclops.functionaljava.ListKind;
import static cyclops.companion.functionaljava.Lists.Instances.functor;
import static cyclops.companion.functionaljava.Lists.Instances.zippingApplicative;

ListKind> listFn = ListKind.widen(List.list((Lambda.λ((Integer i) ->i*2)) .convert(ListKind::narrowK);

List list = zippingApplicative().ap(listFn,functor().map((String v)->v.length(), widen(List.list("hello")))) .convert(ListKind::narrow);

//List.list("hello".length()*2))

There are a number of integration modules for cyclops-react, they are

This screencast gives an overview of how cyclops can help integrate and provide abstractions across the datatypes in the above libraries. Unifying the cambrian explosion with cyclops-react

Getting cyclops-react

  • Maven Central : cyclops-react

Gradle

where x.y.z represents the latest version

compile 'com.oath.simplereact:cyclops-react:x.y.z'

Maven

    com.oath.simplereact
    cyclops-react
    x.y.z

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.