Skip to content

Commit

Permalink
updated fibonacci number algorithm for javadoc and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
evpl committed Mar 16, 2024
1 parent ac91346 commit ef8e30a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ returning the result.

```
int value = letIntRec(10, (n, func) -> {
if (n < 2) {
return n;
if (n <= 1) {
return 1;
} else {
return n * func.apply(n - 1);
}
return func.apply(n - 1) + func.apply(n - 2);
});
```

Expand Down Expand Up @@ -302,10 +303,11 @@ new MyBuilder()

```
int value = letIntRec(10, (n, func) -> {
if (n < 2) {
return n;
if (n <= 1) {
return 1;
} else {
return n * func.apply(n - 1);
}
return func.apply(n - 1) + func.apply(n - 2);
});
```

Expand Down
37 changes: 21 additions & 16 deletions src/main/java/com/plugatar/jkscope/JKScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@
* opt("value").takeUnless(it -> it.isEmpty()).takeIf(it -> it.length() < 100).letIt(it -> System.out.println(it));
*
* int value = letIntRec(10, (n, func) -> {
* if (n < 2) {
* return n;
* if (n <= 1) {
* return 1;
* } else {
* return n * func.apply(n - 1);
* }
* return func.apply(n - 1) + func.apply(n - 2);
* });
*
* with(new MyObject(), it -> {
Expand Down Expand Up @@ -573,10 +574,11 @@ static double letDouble(final double value,
* Performs given function block recursively and returns result.
* <pre>{@code
* Integer value = letRec(10, (n, func) -> {
* if (n < 2) {
* return n;
* if (n <= 1) {
* return 1;
* } else {
* return n * func.apply(n - 1);
* }
* return func.apply(n - 1) + func.apply(n - 2);
* });
* }</pre>
*
Expand All @@ -598,10 +600,11 @@ static <V> V letRec(final V initialValue,
* Performs given function block recursively and returns {@code int}-valued result.
* <pre>{@code
* int value = letIntRec(10, (n, func) -> {
* if (n < 2) {
* return n;
* if (n <= 1) {
* return 1;
* } else {
* return n * func.apply(n - 1);
* }
* return func.apply(n - 1) + func.apply(n - 2);
* });
* }</pre>
*
Expand All @@ -621,11 +624,12 @@ static int letIntRec(final int initialValue,
/**
* Performs given function block recursively and returns {@code long}-valued result.
* <pre>{@code
* long value = letLongRec(10L, (n, func) -> {
* if (n < 2L) {
* return n;
* long value = letLongRec(10, (n, func) -> {
* if (n <= 1L) {
* return 1L;
* } else {
* return n * func.apply(n - 1L);
* }
* return func.apply(n - 1L) + func.apply(n - 2L);
* });
* }</pre>
*
Expand All @@ -646,10 +650,11 @@ static long letLongRec(final long initialValue,
* Performs given function block recursively and returns {@code double}-valued result.
* <pre>{@code
* double value = letDoubleRec(10.0, (n, func) -> {
* if (n < 2.0) {
* return n;
* if (n <= 1.0) {
* return 1.0;
* } else {
* return n * func.apply(n - 1.0);
* }
* return func.apply(n - 1.0) + func.apply(n - 2.0);
* });
* }</pre>
*
Expand Down

0 comments on commit ef8e30a

Please sign in to comment.