Created
November 30, 2012 05:13
-
-
Save jnape/4173874 to your computer and use it in GitHub Desktop.
Fibonacci numbers using Streams in Dynamic-Collections v1.2.9
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
package com.jnape.dynamiccollection; | |
import com.jnape.dynamiccollection.lambda.Function; | |
import com.jnape.dynamiccollection.list.CachingStream; | |
import com.jnape.dynamiccollection.list.DynamicList; | |
import com.jnape.dynamiccollection.list.Stream; | |
import static com.jnape.dynamiccollection.lambda.library.numeric.accumulator.Add.add; | |
import static com.jnape.dynamiccollection.list.NumericDynamicArrayList.numbers; | |
public class Fibonacci { | |
public static void main(String[] args) { | |
Stream<Number> fibs = new CachingStream<Number>(numbers(0d, 1d), new Function<DynamicList<Number>, Number>() { | |
@Override | |
public Number apply(DynamicList<Number> numbers) { | |
return add(numbers.get(-1), numbers.get(-2)); | |
} | |
}); | |
System.out.println(fibs.take(1000).last()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment