Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created February 11, 2013 17:54
Show Gist options
  • Select an option

  • Save alexandreaquiles/4756153 to your computer and use it in GitHub Desktop.

Select an option

Save alexandreaquiles/4756153 to your computer and use it in GitHub Desktop.
Lazy Fibonacci implementation using the Totally Lazy library.
import static com.googlecode.totallylazy.Callables.first;
import static com.googlecode.totallylazy.Computation.computation;
import static com.googlecode.totallylazy.Pair.reduceLeftShift;
import com.googlecode.totallylazy.Pair;
import com.googlecode.totallylazy.Sequence;
import com.googlecode.totallylazy.numbers.Sum;
public class TotallyLazyFibonacci {
public static Sequence<Number> fibonacciSequence =
computation(Pair.<Number, Number>pair(0, 1), reduceLeftShift(new Sum())).map(first(Number.class));
public static void main(String[] args) {
System.out.println(fibonacciSequence.take(25).toList());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment