Skip to content

Custom operators and type conversions

johnmcclean-aol edited this page Nov 21, 2016 · 2 revisions

All cyclops-react types implement the To interface, the goal of To is to allow fluent conversion from the type that implements To to any other. A fluent-custom operation is simply a special case that converts the source type back to another instance of the same type.

Custom conversion

Example: if we define a static toStream method on a Streams class we can use it to fluently convert from a target type that implements To to a Stream.

   api.doThis(a->a*2)
      .doThat(a->a+2)
      .to(Streams::toStream)
      .peek(System.out::println);

Custom operators

Similarly we can define and fluently plugin custom operators to any type that implements To

import static my.custom.operators.customZip;

ReactiveSeq.of(1,2,3)
           .to(customZip(Stream.of('a','b','c'))
           .forEach(System.out::println)
Clone this wiki locally