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.

pub version points likes popularity sdk platform Awesome Flutter

Tailrec (anyone-dart-tailrec) #

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. inspired by kotlin tailrec keywords. (https://kotlinlang.org/docs/functions.html#tail-recursive-functions)

If you like my module, please buy me a coffee.

More and more tiny and useful GitHub action modules are on the way. Please donate to me. I accept a part-time job contract. if you need, please contact me: zhang_nan_163@163.com

How to use #

Math concepts 高中数学中的函数"不动点" #

tailrec

Calculate fixed point for cos(x) #

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);
}

Conclusion #

cos(x) fixed point approximately equal to 0.7390851332151607

cos(0.7390851332151607) ≈ 0.7390851332151607

Donation #

PalPal: https://paypal.me/nzhang4

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