Skip to content

Commit

Permalink
Formatting changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
runarorama committed Feb 7, 2012
1 parent 6c21646 commit a24b159
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions core/src/main/java/fj/control/Trampoline.java
Expand Up @@ -149,6 +149,7 @@ public Trampoline<A> f(final A a) {

/**
* Constructs a leaf computation that results in the given value.
*
* @param a The value of the result.
* @return A trampoline that results in the given value.
*/
Expand All @@ -158,6 +159,7 @@ public static <A> Trampoline<A> pure(final A a) {

/**
* Suspends the given computation in a thunk.
*
* @param a A trampoline suspended in a thunk.
* @return A trampoline whose next step runs the given thunk.
*/
Expand All @@ -180,13 +182,15 @@ public Trampoline<A> f(final P1<Trampoline<A>> trampolineP1) {

/**
* Binds the given continuation to the result of this trampoline.
*
* @param f A function that constructs a trampoline from the result of this trampoline.
* @return A new trampoline that runs this trampoline, then continues with the given function.
*/
public abstract <B> Trampoline<B> bind(final F<A, Trampoline<B>> f);

/**
* Maps the given function across the result of this trampoline. Monadic bind.
*
* @param f A function that gets applied to the result of this trampoline.
* @return A new trampoline that runs this trampoline, then applies the given function to the result.
*/
Expand Down Expand Up @@ -237,23 +241,25 @@ public Either<P1<Trampoline<A>>, A> f(final Trampoline<A> aTrampoline) {

/**
* Runs a single step of this computation.
*
* @return The next step of this compuation.
*/
public abstract Either<P1<Trampoline<A>>, A> resume();

/**
* Runs this computation all the way to the end, in constant stack.
*
* @return The end result of this computation.
*/
@SuppressWarnings("LoopStatementThatDoesntLoop")
public A run() {
Trampoline<A> current = this;
while (true) {
final Either<P1<Trampoline<A>>, A> x = current.resume();
for (final P1<Trampoline<A>> t: x.left()) {
for (final P1<Trampoline<A>> t : x.left()) {
current = t._1();
}
for (final A a: x.right()) {
for (final A a : x.right()) {
return a;
}
}
Expand All @@ -272,7 +278,7 @@ public Trampoline<B> f(final F<A, B> f) {
}
});
}

/**
* Binds the given function across the result of this Trampoline and the given Trampoline.
*
Expand All @@ -283,7 +289,7 @@ public Trampoline<B> f(final F<A, B> f) {
public final <B, C> Trampoline<C> bind(final Trampoline<B> lb, final F<A, F<B, C>> f) {
return lb.apply(map(f));
}


/**
* Promotes the given function of arity-2 to a function on Trampolines.
Expand All @@ -298,6 +304,6 @@ public Trampoline<C> f(final Trampoline<A> as, final Trampoline<B> bs) {
}
});
}


}

0 comments on commit a24b159

Please sign in to comment.