Is there an equivalent of Scala's Either in Java 8?

后端 未结 8 775
南旧
南旧 2020-11-28 23:00

Just like java.util.Optional in Java 8 is (somewhat) equivalent to Scala\'s Option[T] type, is there an equivalent to Scala\'s Eithe

8条回答
  •  野性不改
    2020-11-28 23:39

    At the time of writing, vavr (formerly javaslang) is probably the most popular functional Java 8 library. It is pretty similar to lambda-companion's Either in my other answer.

    Either value = compute().right().map(i -> i * 2).toEither();
    

提交回复
热议问题