dart_essentials library

Dart Essentials - a collection of classes and functions to make Dart development easier.

Mostly inspired by python

Classes

EasyComparable<T>
An easy way to implement Comparable in a way that compareTo aggrees with > and == operators
Range
Iterable of integers; Range is open ended on the right
SpecificComparable<T, U extends Object>
An easy way to implement Comparable in a way that compareTo aggrees with > and == operators
StrictComparable<T extends Object>
An easy way to implement Comparable in a way that compareTo aggrees with > and == operators
string
static class to be used like in python The constants defined as in python https://docs.python.org/3/library/string.html

Mixins

Closeable
Similar to java Closeable, or python context manager, or c# IDisposable

Extensions

CloseableExtensions on C
Extension methods for Closeable
IterableExtraExtensions on Iterable<T>
adds utility methods to Iterable
PairExtraExtensions on Pair<int, T>
syntax sugar to use Pair in a more meaningful way with IterableExtraExtensions.enumerate

Properties

infiniteRange Iterable<int>
creates a lazy Iterable that will produce integers until error
no setter
isDebugMode bool
Similar to Flutter's kDebugMode, but without relying on vm's properties.
no setter

Functions

enumerate<T>(Iterable<T> iterable, [int start = 0]) Iterable<Pair<int, T>>
top-level function matching the behaviour of the Python enumerate function
eval<T>(String expression, {T decoder(String raw)?}) Future<T>
evaluates a dart expression.
extendedJsonDecode(String encoded) → dynamic
a wrapper around jsonDecode to upcast types from dynamic to primitives
extendedJsonEncode(dynamic value) → dynamic
a wrapper around jsonEncode which resolves lazy iterators
range(int a, [int? b, int? c]) Range
Python like range function
sleep(num seconds) Future<void>
wrapper around Future.delayed to have a simpler syntax
useCloseable<R, C extends Closeable>(C resource, R fn(C p0)) → R
Runs passed function and closes this resource after it Closes the resource even if the function throws. The first exception thrown is propagated, if both the function and the close throw, the exception from the function is propagated
useCloseableAsync<R, C extends Closeable>(C resource, FutureOr<R> fn(C p0)) Future<R>
Runs passed function and closes this resource after it Closes the resource even if the function throws. The first exception thrown is propagated, if both the function and the close throw, the exception from the function is propagated
zip<A, B>(Iterable<A> iterable1, Iterable<B> iterable2) Iterable<Pair<A, B>>
top-level function matching the behaviour of the Python zip function