aol / cyclops-integration

Home of the cyclops integration modules : support for Scala, Clojure, RxJava (1+2), Reactor, FunctionalJava, Guava, Dexx & Vavr
http://cyclops-react.io
MIT License
443 stars 51 forks source link

[cyclops-javaslang] For comprehension does not work work Either<L, R> #259

Closed slnowak closed 7 years ago

slnowak commented 7 years ago

The following test

 @Test
    public void shouldComprehendEitherExpressions() throws Exception {
        // when
        final Either<Exception, String> wrapsCappuccino = For
                .iterable(grind("arabica beans"))
                .iterable(ground -> heatWater(new Water(25)))
                .iterable(ground -> water -> brew(ground, water))
                .iterable(ground -> water -> espresso -> frothMilk("milk"))
                .yield(ground -> water -> espresso -> foam -> combine(espresso, foam))
                .unwrap();

        // then
        assertThat(
                wrapsCappuccino.get(),
                equalTo("cappuccino")
        );
    }

fails with

java.lang.ClassCastException: javaslang.control.Either$Right cannot be cast to javaslang.control.Either$RightProjection

this happens because EitherComprehender explicitely calls either.right() which in turn returns RightProjection.

The following should fix that: https://github.com/aol/cyclops/pull/260

johnmcclean commented 7 years ago

Awesome! Thanks a million for reporting and fixing this!!

johnmcclean commented 7 years ago

This has been released in 8.4.2. - many thanks for the fix!