Search in sources :

Example 1 with CompletableEither

use of cyclops.control.LazyEither.CompletableEither in project cyclops by aol.

the class CompletableEitherTest method completableNoneTest.

@Test
public void completableNoneTest() {
    CompletableEither<Integer, Integer> completable = LazyEither.either();
    LazyEither<Throwable, Integer> mapped = completable.map(i -> i * 2).flatMap(i -> LazyEither.right(i + 1));
    completable.completeExceptionally(new NoSuchElementException());
    mapped.printOut();
    assertThat(mapped.isPresent(), equalTo(false));
    assertThat(mapped.leftOrElse(null), instanceOf(NoSuchElementException.class));
}
Also used : Arrays(java.util.Arrays) cyclops.control(cyclops.control) Streams(cyclops.companion.Streams) Monoids(cyclops.companion.Monoids) CompletableEither(cyclops.control.LazyEither.CompletableEither) Monoid(cyclops.function.Monoid) Test(org.junit.Test) Future(cyclops.control.Future) Collectors(java.util.stream.Collectors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Mutable(com.oath.cyclops.util.box.Mutable) Stream(java.util.stream.Stream) Ignore(org.junit.Ignore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) StreamSupport(java.util.stream.StreamSupport) Semigroups(cyclops.companion.Semigroups) NoSuchElementException(java.util.NoSuchElementException) Assert(org.junit.Assert) Reducers(cyclops.companion.Reducers) Before(org.junit.Before) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 2 with CompletableEither

use of cyclops.control.LazyEither.CompletableEither in project cyclops by aol.

the class EitherTest method completableNoneTest.

@Test
public void completableNoneTest() {
    CompletableEither<Integer, Integer> completable = LazyEither.either();
    LazyEither<Throwable, Integer> mapped = completable.map(i -> i * 2).flatMap(i -> LazyEither.right(i + 1));
    completable.completeExceptionally(new NoSuchElementException());
    mapped.printOut();
    assertThat(mapped.isPresent(), equalTo(false));
    assertThat(mapped.leftOrElse(null), instanceOf(NoSuchElementException.class));
}
Also used : Arrays(java.util.Arrays) PersistentSet(com.oath.cyclops.types.persistent.PersistentSet) LazyEither(cyclops.control.LazyEither) Matchers.not(org.hamcrest.Matchers.not) Trampoline(cyclops.control.Trampoline) Monoids(cyclops.companion.Monoids) HashSet(cyclops.data.HashSet) Future(cyclops.control.Future) Seq(cyclops.data.Seq) StreamSupport(java.util.stream.StreamSupport) Semigroups(cyclops.companion.Semigroups) NoSuchElementException(java.util.NoSuchElementException) Before(org.junit.Before) Maybe(cyclops.control.Maybe) cyclops.control(cyclops.control) Spouts(cyclops.reactive.Spouts) Streams(cyclops.companion.Streams) CompletableEither(cyclops.control.LazyEither.CompletableEither) Monoid(cyclops.function.Monoid) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) Mutable(com.oath.cyclops.util.box.Mutable) Stream(java.util.stream.Stream) Ignore(org.junit.Ignore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Assert(org.junit.Assert) Reducers(cyclops.companion.Reducers) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Aggregations

Mutable (com.oath.cyclops.util.box.Mutable)2 Monoids (cyclops.companion.Monoids)2 Reducers (cyclops.companion.Reducers)2 Semigroups (cyclops.companion.Semigroups)2 Streams (cyclops.companion.Streams)2 cyclops.control (cyclops.control)2 Future (cyclops.control.Future)2 CompletableEither (cyclops.control.LazyEither.CompletableEither)2 Monoid (cyclops.function.Monoid)2 Arrays (java.util.Arrays)2 NoSuchElementException (java.util.NoSuchElementException)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 StreamSupport (java.util.stream.StreamSupport)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 Ignore (org.junit.Ignore)2