xrange 0.0.6

pub package Gitter Chat

This is a fork of Interval library

XRange lib #

Provides the Range class, a contiguous set of values, and the ZRange class, that along with functionality of Range class can also generate values of arithmetic progression in a specific diapason. This range can contain just integer numbers, that's why Z is used as a prefix for the class name (the letter Z denotes the set of all integers in mathematics).

If a range contains two values, it also contains all values between them. It may have an upper and lower bound, and those bounds may be open or closed.

Usage #

Range #

import 'package:xrange/range.dart';

void main() {
  final date1 = DateTime(2015);
  final date2 = DateTime(2021);
  final dates = Range<DateTime>.closed(date1, date2);

  if (dates.contains(DateTime.now())) {
    print('Hi, contemporary!');
  } else {
    print('Apparently, you are from the future!');
  }
}

ZRange #

import 'package:xrange/zrange.dart';

void main() {
  final range = ZRange.closed(-10, 10);
  
  for (final value in range.values(step: 2)) {
    print(value); // it yields numbers from -10 to 10 with step equals 2
  }
}

Pay attention to values method - it is a generator function, so use all the benefits of this.

Changelog #

0.0.6 #

  • ZRange: firstValue, lastValue, length calculation fixed

0.0.5 #

  • README updated: badges added, text corrected

0.0.4 #

  • ZRange: length calculation fixed

0.0.3 #

  • ZRange class introduced

0.0.2 #

  • pubspec.yaml: author section corrected

0.0.1 #

  • Interval renamed to Range
  • Analysis options added

example/main.dart

import 'package:xrange/range.dart';
import 'package:xrange/zrange.dart';

void range() {
  final date1 = DateTime(2015);
  final date2 = DateTime(2021);
  final dates = Range<DateTime>.closed(date1, date2);

  if (dates.contains(DateTime.now())) {
    print('Hi, contemporary!');
  } else {
    print('Apparently, you are from the future!');
  }
}

void zrange() {
  final range = ZRange.closed(-10, 10);
  for (final value in range.values(step: 2)) {
    print(value); // it yields numbers from -10 to 10 with step equals 2
  }
}

void main() {
  range();
  zrange();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  xrange: ^0.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:xrange/range.dart';
import 'package:xrange/zrange.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
41
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Health suggestions

Fix lib/zrange.dart. (-0.50 points)

Analysis of lib/zrange.dart reported 1 hint:

line 52 col 63: DO use curly braces for all flow control structures.

Format lib/range.dart.

Run dartfmt to format lib/range.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
Dev dependencies
build_runner ^1.1.2
build_test ^0.10.2
pedantic 1.1.0
test ^1.2.0

Admin