All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rouz.scratch.Fib Maven / Gradle / Ivy

package io.rouz.scratch;

import io.rouz.task.Task;
import io.rouz.task.TaskContext;
import io.rouz.task.dsl.TaskBuilder;

/**
 * Simple fibonacci implementations
 */
final class Fib {

  public static void main(String[] args) {
    Task fib92 = create(92);
    TaskContext taskContext = TaskContext.inmem();
    TaskContext.Value value = taskContext.evaluate(fib92);

    value.consume(f92 -> System.out.println("fib(92) = " + f92));
  }

  static Task create(long n) {
    TaskBuilder fib = Task.named("Fib", n).ofType(Long.class);
    if (n < 2) {
      return fib
          .process(() -> n);
    } else {
      return fib
          .in(() -> Fib.create(n - 1))
          .in(() -> Fib.create(n - 2))
          .process(Fib::fib);
    }
  }

  static long fib(long a, long b) {
    System.out.println("Fib.process(" + a + " + " + b + ")");
    return a + b;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy