Created
November 13, 2016 21:18
-
-
Save johnmcclean/fb1735b49e6206396bd5792ca11ba7b2 to your computer and use it in GitHub Desktop.
Tail call optimized / stackless recursion fibonacci sequence in Java 8 using cyclops-react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.aol.cyclops.control.Trampoline.done; | |
import static com.aol.cyclops.control.Trampoline.more; | |
public void fib() { | |
for(int i=0;i<100_000;i++) | |
System.out.println(fibonacci(i, 0l, 1l).get()); | |
} | |
public Trampoline<Long> fibonacci(Integer count, Long a, Long b) { | |
return count==0 ? done(a) : more(()->fibonacci (count - 1, b, a + b)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment