tailrec 1.0.2 copy "tailrec: ^1.0.2" to clipboard
tailrec: ^1.0.2 copied to clipboard

This package help you to convert recursive function into the while-loop codes. so that program won't meet out of memory that caused by stack overflow.

example/tailrec_example.dart

/*
 * @Author: Edward Zhang 
 * @Date: 2022-10-13 09:30:38 
 * @Last Modified by: Edward Zhang
 * @Last Modified time: 2022-10-13 11:10:32
 */
import 'dart:core';
import 'package:tailrec/tailrec.dart';
import 'dart:math';

final eps = 1E-10; //precision

void main() {
  final firstValue = 1;

  var tailrec = Tailrec(
    conditionCallback: <double>(dynamic x) {
      final y = cos(x);
      final temp = (x - y).abs();
      return temp < eps;
    },
    recurringParamComputeCallback: <double>(dynamic x) {
      return cos(x) as double;
    },
    resultCallback: <double>(dynamic x) {
      return x;
    },
  );

  final fixedPoint = tailrec.apply(firstValue);
  print(fixedPoint);
}
4
likes
140
pub points
0%
popularity

Publisher

unverified uploader

This package help you to convert recursive function into the while-loop codes. so that program won't meet out of memory that caused by stack overflow.

Homepage

Documentation

API reference

License

GPL-3.0 (LICENSE)

More

Packages that depend on tailrec