positive_num 1.0.8 copy "positive_num: ^1.0.8" to clipboard
positive_num: ^1.0.8 copied to clipboard

The package contains an immutable value object called PositiveNum that encapsulates a positive number (any number greater than 0) which can be int or double. PositiveNum guarantees that its value is a [...]

example/positive_num_example.dart

// ignore_for_file: unused_local_variable

import 'package:positive_num/positive_num.dart';

void main() {
  example1();
  example2();
}

void example1() {
  var someNumber = 1;
  //
  final (:error, :instance) = PositiveNum.create(someNumber);
  if (instance != null) {
    final positiveNum = instance;
    print('Created a PositiveNum instance with $positiveNum value.');
  } else {
    print('Error. $error');
  }
}

void example2() {
  const nums1 = [-5, -5.0, -0.001, -0.0, 0.0, 0];
  const nums2 = [0.1, 1, 999999];
  const nums3 = [double.nan, double.negativeInfinity];
  const nums4 = [double.minPositive, double.maxFinite, double.infinity];
  //
  for (final n in [...nums1, ...nums2, ...nums3, ...nums4]) {
    switch (PositiveNum.create(n)) {
      case (:String? error, :PositiveNum instance):
        final positiveNum = instance;
        print('SUCCESS [try $n] PositiveNum created with $positiveNum value.');
        break;
      case (:String error, :PositiveNum? instance):
        print('FAILURE [try $n] PositiveNum was not created. $error');
        break;
    }
  }
}
4
likes
0
pub points
0%
popularity

Publisher

unverified uploader

The package contains an immutable value object called PositiveNum that encapsulates a positive number (any number greater than 0) which can be int or double. PositiveNum guarantees that its value is always positive and can't be change after creation. PositiveNum can't be created with 0 or negative value.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on positive_num