devlaf / tco

A poor-man's tail-call optimization and a little trampolining

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TCO

About

JAVA doesn't do tail-call optimization on recursive operations. But with a little java 8, we can kinda hack it together at runtime.

There are some more comprehensive libraries out there for adding functional goodies to java that do similar things for TCO along with much more (see aol/cyclops for instance.) This package simply does the one thing.

Disclaimer

This is just for funsies, production java code should probably just be boring and iterative.

Usage

Definine the recursive func as a RuntimeOptimizedTailCall using the constructor there. At that point, you can call the getResult() method to execute the computation. See javadocs for explanations of how to construct the RuntimeOptimizedTailCall.

Example

See example code here

About

A poor-man's tail-call optimization and a little trampolining

License:MIT License


Languages

Language:Java 100.0%