Last active
December 12, 2015 09:59
-
-
Save alexandreaquiles/4756087 to your computer and use it in GitHub Desktop.
Lazy Fibonacci implementation in Java using the Functional Java library.
This file contains hidden or 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 fj.F2; | |
| import fj.data.List; | |
| import fj.data.Stream; | |
| public class FunctionalJavaFibonacci { | |
| public static final Stream<Long> fibonacciSequence = new F2<Long, Long, Stream<Long>>() { | |
| public Stream<Long> f(final Long a, final Long b) { | |
| return Stream.cons(a, curry().f(b).lazy().f(a + b)); | |
| } | |
| }.f(0L, 1L); | |
| public static void main(String[] args) { | |
| List<Long> fibonacciUpto25 = fibonacciSequence.take(25).toList(); | |
| System.out.println(fibonacciUpto25); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment