xrange 0.0.9

Dart native js
Flutter Android iOS web

Provides classes and methods allowing to work with ranges

Build Status Coverage Status pub package Gitter Chat

This is a fork of Interval library

XRange lib #

Provides the Range class, a contiguous set of values, and the NumRange class, that along with functionality of Range class can also generate values of arithmetic progression in a specific diapason.

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.

Also the library contains integers generator function, that is based on NumRange class. It produces integer values from a specific closed diapason.

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

NumRange #

import 'package:xrange/num_range.dart';

void main() {
  final range = NumRange.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.

integers #

import 'package:xrange/integers.dart';

void main() {
  for (final value in integers(-10, 10)) {
    print(value); // it yields numbers from -10 to 10 with step equals 2
  }
}

The integers function returns a lazy iterable, thus it consumes little memory, since the whole collection is not being generated when integers is called.

0
likes
90
pub points
84%
popularity

Provides classes and methods allowing to work with ranges

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

ilgyrd@gmail.com

License

BSD (LICENSE)

Dependencies

injector

More

Packages that depend on xrange