Iso
+
+## [2.1.1] - 2018-01-16
+### Changed
- ***Breaking Change***: Moved `Trampoline` and `RecursiveResult` to better package
## [2.1.0] - 2018-01-14
@@ -254,7 +300,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
- `Monadic/Dyadic/TriadicFunction`, `Predicate`, `Tuple2`, `Tuple3`
- `Functor`, `BiFunctor`, `ProFunctor`
-[Unreleased]: https://github.com/palatable/lambda/compare/lambda-2.1.0...HEAD
+[Unreleased]: https://github.com/palatable/lambda/compare/lambda-2.1.1...HEAD
+[2.1.1]: https://github.com/palatable/lambda/compare/lambda-2.1.0...lambda-2.1.1
[2.1.0]: https://github.com/palatable/lambda/compare/lambda-2.0.0...lambda-2.1.0
[2.0.0]: https://github.com/palatable/lambda/compare/lambda-1.6.3...lambda-2.0.0
[1.6.3]: https://github.com/palatable/lambda/compare/lambda-1.6.2...lambda-1.6.3
diff --git a/README.md b/README.md
index 4ff8f81e0..dcfe6df73 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
[](https://travis-ci.org/palatable/lambda)
[](http://search.maven.org/#search%7Cga%7C1%7Ccom.jnape.palatable.lambda)
-Functional patterns for Java 8
+Functional patterns for Java
#### Table of Contents
@@ -57,14 +57,14 @@ Add the following dependency to your:
Eithers are both Functors over their right value and
- * Bifunctors over both values.
+ * The binary tagged union, implemented as a specialized {@link CoProduct2}. General semantics tend to connote "success"
+ * values via the right value and "failure" values via the left values. {@link Either}s are both {@link Monad}s and
+ * {@link Traversable}s over their right value and are {@link Bifunctor}s over both values.
*
* @param leftFn to it, wrap it in a left value, and return it.
+ *
+ * @param runnable the runnable
+ * @param leftFn a function mapping E to L
+ * @param consumer; otherwise, do nothing.
*
@@ -158,7 +151,7 @@ public final Maybe peek(Consumer consumer) {
* @return "Just" the right value, or nothing
*/
public static Maybe fromEither(Either, A> either) {
- return either.match(constantly(nothing()), Maybe::just);
+ return either.toMaybe();
}
/**
@@ -169,7 +162,7 @@ public static Maybe fromEither(Either, A> either) {
* @return the equivalent Maybe instance
*/
public static Maybe fromOptional(Optional extends A> optional) {
- return optional.map(id()).map(Maybe::just).orElse(Maybe.nothing());
+ return optional.map(Maybe::just).orElse(Maybe.nothing());
}
/**
@@ -223,10 +216,11 @@ public Maybe flatMap(Function super A, ? extends Monad> f) {
}
@Override
- public Applicative{@link CoProduct2}<A, B>) and its product ({@link
+ * Tuple2}<A, B>), represented as a {@link CoProduct3}<A, B, {@link Tuple2}<A,
+ * B>>.
+ *
+ * @param the first possible type
+ * @param the second possible type
+ */
+public abstract class These implements CoProduct3, These>, Monad>, Bifunctor>, Traversable> {
+
+ private These() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final A in a {@link These}.
+ *
+ * @param a the value
+ * @param the first possible type
+ * @param the second possible type
+ * @return the wrapped value as a {@link These}<A,B>
+ */
+ public static These a(A a) {
+ return new _A<>(a);
+ }
+
+ /**
+ * Static factory method for wrapping a value of type B in a {@link These}.
+ *
+ * @param b the value
+ * @param the first possible type
+ * @param the second possible type
+ * @return the wrapped value as a {@link These}<A,B>
+ */
+ public static These b(B b) {
+ return new _B<>(b);
+ }
+
+ /**
+ * Static factory method for wrapping a value of type A and a value of type B in a {@link
+ * These}.
+ *
+ * @param a the first value
+ * @param b the second value
+ * @param the first possible type
+ * @param the second possible type
+ * @return the wrapped values as a {@link These}<A,B>
+ */
+ public static These both(A a, B b) {
+ return new Both<>(tuple(a, b));
+ }
+
+ private static final class _A extends These {
+
+ private final A a;
+
+ private _A(A a) {
+ this.a = a;
+ }
+
+ @Override
+ public trying/catching/ensuring, respectively.
+ *
+ * @param throwableType and map it to a success value.
+ *
+ * @param throwableType the {@link Throwable} (sub)type to be caught
+ * @param recoveryFn the function mapping the {@link Throwable} to the result
+ * @param T satisfying predicate and map it to a success value.
+ *
+ * @param predicate the predicate
+ * @param recoveryFn the function mapping the {@link Throwable} to the result
+ * @return a new {@link Try} instance around either the original successful result or the mapped result
+ */
+ public final Tryfinally.
+ *
+ * If the runnable runs successfully, the result is preserved as is. If the runnable itself throws, and the result
+ * was a success, the result becomes a failure over the newly-thrown {@link Throwable}. If the result was a failure
+ * over some {@link Throwable} t1, and the runnable throws a new {@link Throwable} t2, the
+ * result is a failure over t1 with t2 added to t1 as a suppressed exception.
+ *
+ * @param runnable the runnable block of code to execute
+ * @return the same {@link Try} instance if runnable completes successfully; otherwise, a {@link Try} conforming to
+ * rules above
+ */
+ public final Tryfn and
+ * return the result.
+ *
+ * @param fn the function mapping the potential {@link Throwable} T to A
+ * @return a success value
+ */
+ public final A recover(Function super T, ? extends A> fn) {
+ return match(fn, id());
+ }
+
+ /**
+ * If this is a failure, return the wrapped value. Otherwise, apply the success value to fn and return
+ * the result.
+ *
+ * @param fn the function mapping the potential A to T
+ * @return a failure value
+ */
+ public final T forfeit(Function super A, ? extends T> fn) {
+ return match(id(), fn);
+ }
+
+ /**
+ * If this is a success value, return it. Otherwise, rethrow the captured failure.
+ *
+ * @return possibly the success value
+ * @throws T the possible failure
+ */
+ public abstract A orThrow() throws T;
+
+ /**
+ * If this is a success, wrap the value in a {@link Maybe#just} and return it. Otherwise, return {@link
+ * Maybe#nothing()}.
+ *
+ * @return {@link Maybe} the success value
+ */
+ public final Maybe toMaybe() {
+ return match(__ -> nothing(), Maybe::just);
+ }
+
+ /**
+ * If this is a success, wrap the value in a {@link Either#right} and return it. Otherwise, return the {@link
+ * Throwable} in an {@link Either#left}.
+ *
+ * @return {@link Either} the success value or the {@link Throwable}
+ */
+ public final Eithersupplier, returning a success A or a failure of the thrown {@link Throwable}.
+ *
+ * @param supplier the supplier
+ * @param runnable, returning a success {@link Unit} or a failure of the thrown {@link Throwable}.
+ *
+ * @param runnable the runnable
+ * @param null.
+ */
+public final class Unit {
+
+ /**
+ * The singleton instance.
+ */
+ public static final Unit UNIT = new Unit();
+
+ private Unit() {
+ }
+
+ @Override
+ public String toString() {
+ return "Unit{}";
+ }
+}
diff --git a/src/main/java/com/jnape/palatable/lambda/adt/choice/Choice2.java b/src/main/java/com/jnape/palatable/lambda/adt/choice/Choice2.java
index f38f681cf..5276adb04 100644
--- a/src/main/java/com/jnape/palatable/lambda/adt/choice/Choice2.java
+++ b/src/main/java/com/jnape/palatable/lambda/adt/choice/Choice2.java
@@ -84,11 +84,11 @@ public final