项目作者: AKushWarrior

项目描述 :
A math library for Dart, similar to Guava for Java.
高级语言: Dart
项目地址: git://github.com/AKushWarrior/starfruit.git
创建时间: 2019-08-30T23:08:13Z
项目社区:https://github.com/AKushWarrior/starfruit

开源协议:Mozilla Public License 2.0

下载


Starfruit

A library containing useful utilities, efficiencies, and
abstractions to improve over the Dart SDK and dart:math. It takes heavy
inspiration from Guava (by Google) for Java, and ports some functions from
it.


It takes time, effort, and mental power to keep this package updated, useful, and
improving. If you used or are using the package, I’d appreciate it if you could spare a few
dollars to help me continue to do so.

PayPal


Classes

Note: https://pub.dev/documentation/starfruit/latest/starfruit/starfruit-library.html
is auto-generated dartdocs. This has a more detailed rundown of every class
and method. It’s impossible to list every method offered and its purpose,
so I won’t try. You should use the usage examples and documentation to understand
the utilities of this library. For here, I’m just offering basic details on how to
instantiate every class.

StarMathUtils (mathUtils)

To use, call methods on the singleton instance mathUtils (e.g. mathUtils.chunks([1, 2, 3, 4, 5, 6], 2) ).

StarCollectionUtils (collectionUtils)

To use, call methods on the singleton instance collectionUtils (e.g. collectionUtils.chunks([1, 2, 3, 4, 5, 6], 2) ).

StarStats (List<num>)

To use, collect a list of numerical input data. You can then call StarStats methods on it, because
StarStats is defined as an extension on List.

StarStatsXY (Map<num,num> of points)

To use, collect input data formatted {x1: y1, x2: y2, x3: y3, …}. You can then call StarStatsXY methods
on it, because StarStatsXY is defined as an extension on Map.


Usage Examples

Math Utilities:
  1. import 'package:starfruit/starfruit.dart';
  2. main() {
  3. /Round to 2 decimal places
  4. //Ceiling and flooring to decimal places is also available
  5. print('Round 3.5634 to 2 decimal places:');
  6. print(mathUtils.roundToDouble(3.5634, 2));
  7. print('');
  8. //Power of two check
  9. print('Is 8 a power of two?');
  10. print(mathUtils.isPowerOfTwo(8));
  11. print('');
  12. //Calculate log base 2 of 8
  13. print('Calculate log base 2 of 8:');
  14. print(mathUtils.log(2, 8));
  15. print('');
  16. //double isInteger check
  17. print('Is 6.0 an integer?');
  18. print(mathUtils.isMathematicalInteger(6.0));
  19. print('');
  20. //Calculate 5!
  21. print('Calculate 5 factorial:');
  22. print(mathUtils.factorial(5));
  23. print('');
  24. //Check if 2 is within 3 of 5
  25. print('Is 2 within 3 of 5?');
  26. print(mathUtils.fuzzyEquals(2, 5, 3));
  27. print('');
  28. //Check if 7919 is a prime number
  29. print('Is 7919 prime?');
  30. print(mathUtils.isPrime(7919));
  31. print('');
  32. //LCM of 2 and 7
  33. print('Calculate LCM of 2 and 7:');
  34. print(mathUtils.lcm(2, 7));
  35. print('');
  36. //sinh of 1 radian
  37. print('Calculate sinh of 1 radian:');
  38. print(mathUtils.sinh(1));
  39. print('');
  40. //mean of 3 and 7
  41. print('Calculate mean of 3 and 7:');
  42. print(mathUtils.mean(3,7));
  43. print('');
  44. //nCr where n = 5 and r = 2
  45. print('Calculate the binomial coefficient of 2 and 5:');
  46. print(mathUtils.combinationsOf(5, 2));
  47. print('');
  48. //nPr where n = 5 and r = 2
  49. print('Calculate the permutations of 5 and 2:');
  50. print(mathUtils.permutationsOf(5, 2));
  51. print('');
  52. }
Collection Utilities:
  1. import 'package:starfruit/starfruit.dart';
  2. main() {
  3. //Separate List into chunks
  4. print("Separate List into chunks of 4:");
  5. print(cUtils.chunks([1,2,3,4,5,6,7,8], 4));
  6. print("");
  7. //Collapse List<List<Object>> into just List<Object>
  8. print("Collapse List<List> into List:");
  9. print(cUtils.collapse( [[1,2,3],[4,5,6,7,8]] ));
  10. print("");
  11. //Get every nth object of list
  12. print("Get every 4th object:");
  13. print(cUtils.nth([1,2,3,4,5,6,7,8], 4));
  14. print("");
  15. //Get every n random elements of list
  16. print("Get 5 random elements:");
  17. print(cUtils.random([1,2,3,4,5,6,7,8], 5));
  18. print("");
  19. //Flip keys and values of a map
  20. print("Flip keys and values of a map:");
  21. print(cUtils.flip({1:0, 2:8, 3:4, 0:5}));
  22. print("");
  23. //Zip two Lists into a map
  24. print("Zip two lists into a map:");
  25. print(cUtils.zip([1,2,3,4], [5,6,7,8]));
  26. print("");
  27. //Unzip a map into two lists
  28. print("Unzip a map into two lists:");
  29. print(cUtils.unzip({0:1, 8:2, 4:3, 5:0}));
  30. print("");
  31. }
Stats Utilities:
  1. import 'package:starfruit/starfruit.dart';
  2. main() {
  3. var stats = [1,3,4,5,12,3,4,67,8,0,22];
  4. //median
  5. print("Calculate the median:");
  6. print(stats.median);
  7. print("");
  8. //mean
  9. print("Calculate the mean:");
  10. print(stats.mean);
  11. print("");
  12. //mode
  13. print("Calculate the mode:");
  14. print(stats.mode);
  15. print("");
  16. //variance
  17. print('Calculate the variance:');
  18. print(stats.variance);
  19. print("");
  20. //standard deviation
  21. print("Calculate the standard deviation:");
  22. print(stats.stdDev);
  23. print("");
  24. //cardinality; number of unique elements
  25. print("Calculate the cardinality:");
  26. print(stats.cardinality);
  27. print("");
  28. //7 greatest elements
  29. print("Return the 7 greatest elements:");
  30. print(stats.topElements(7));
  31. print("");
  32. }
XY (Paired) Stats Utilities:
  1. import 'package:starfruit/starfruit.dart';
  2. main() {
  3. var xystats = {2:3, 7:4, 4:6, 8:9, 1:2, 3:5, 11:14, 12:18};
  4. //Get correlation coefficient
  5. print("Calculate correlation coefficient:");
  6. print(xystats.corCoefficient);
  7. print("");
  8. //Get determination coefficent
  9. print("Calculate determination coefficient:");
  10. print(xystats.detCoefficient);
  11. print("");
  12. //Get adjusted determination coefficient
  13. print("Calculate adj. determination coefficient:");
  14. print(xystats.adjDetCoefficient);
  15. print("");
  16. //Get linear regression line
  17. print("Calculate linear regression line in form y = mx + b:");
  18. var lr = xystats.linReg;
  19. print("y = ${lr[0]}x + ${lr[1]}");
  20. print("");
  21. //Get quadratic regression line
  22. print("Calculate quadratic regression line in form y = ax^2 + bx + c:");
  23. var qdr = xystats.quadReg;
  24. print("y = ${qdr[0]}x^2 + ${qdr[1]}x + ${qdr[2]}");
  25. print("");
  26. //Get cubic regression line
  27. print("Calculate cubic regression line in form y = ax^3 + bx^2 + cx + d:");
  28. var cr = xystats.cubicReg;
  29. print("y = ${cr[0]}x^3 + ${cr[1]}x^2 + ${cr[2]}x + ${cr[3]}");
  30. print("");
  31. //Get quartic regression line
  32. print("Calculate quartic regression line in form y = ax^4 + bx^3 + cx^2 + dx + e:");
  33. var qrr = xystats.quarReg;
  34. print("y = ${qrr[0]}x^4 + ${qrr[1]}x^3 + ${qrr[2]}x^2 + ${qrr[3]}x + ${qrr[4]}");
  35. print("");
  36. }

Features and bugs

Please file feature requests and bugs at the issue tracker.


Pub
License
Commits

Starfruit, a set of Dart utility libraries.
©2020 Aditya Kishore
Licensed under the MPL 2.0 (See LICENSE)