# trampoline #

A library for trampolining recursive calls.

# Example 1: #

``````
import 'package:trampoline/trampoline.dart';

TailRec<int> fib(int n) {
if (n < 2) {
return done(n);
} else {
return tailcall(() => fib(n - 1)).flatMap((x) {
return tailcall(() => fib(n - 2)).map((y) {
return (x + y);
});
});
}
}

void main() {
int z = 10;
print("fib(\${z}) is \${fib(z).result}!");
}

``````

# Example 2: #

``````
import 'package:trampoline/trampoline.dart';

TailRec<bool> odd(int n) => n == 0 ? done(false) : tailcall(() => even(n - 1));
TailRec<bool> even(int n) => n == 0 ? done(true) : tailcall(() => odd(n - 1));

void main() {
int z = 1000;
print("\${z} is odd? \${odd(z).result}!");
}

``````

# Changelog #

## 1.0.0 #

• rewritten in object-orientated style

## 0.1.3 #

• replaced recursion with iteration

## 0.1.2 #

• published on github.com

## 0.1.1 #

• improved documentation

example/main.dart

``````import 'package:trampoline/trampoline.dart';

// Example 1

TailRec<int> fib(int n) {
if (n < 2) {
return done(n);
} else {
return tailcall(() => fib(n - 1)).flatMap((x) {
return tailcall(() => fib(n - 2)).map((y) {
return (x + y);
});
});
}
}

// Example 2

TailRec<bool> odd(int n) => n == 0 ? done(false) : tailcall(() => even(n - 1));
TailRec<bool> even(int n) => n == 0 ? done(true) : tailcall(() => odd(n - 1));

void main() {
bool res1;
res1 = even(101).result;
print("Ergebnis von Odd/Even ist \$res1");
for (int z = 20; z < 35; z++) {
num res2;
res2 = fib(z).result;
print("Ergebnis von Fibonacci für \$z ist \$res2");
}
}
``````

## Use this package as a library

### 1. Depend on it

``````
dependencies:
trampoline: ^1.0.0

``````

### 2. Install it

You can install packages from the command line:

with pub:

``````
\$ pub get

``````

with Flutter:

``````
\$ flutter pub get

``````

Alternatively, your editor might support `pub get` or `flutter pub get`. Check the docs for your editor to learn more.

### 3. Import it

Now in your Dart code, you can use:

``````
import 'package:trampoline/trampoline.dart';
``````
 Popularity: Describes how popular the package is relative to other packages. [more] 16 Health: Code health derived from static analysis. [more] 99 Maintenance: Reflects how tidy and up-to-date the package is. [more] 100 Overall: Weighted score of the above. [more] 58

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

• Dart: 2.7.0
• pana: 0.13.4

#### Health issues and suggestions

Document public APIs. (-1 points)

14 out of 14 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

#### Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.6.3