Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.
API Docs are available.
Add Quiver to your project's pubspec.yaml file and run pub get
.
We recommend the following version constraint:
dependencies:
quiver: '>=2.0.0 <3.0.0'
Utilities for working with Futures, Streams and async computations.
collect
collects the completion events of an Iterable
of Future
s into a
Stream
.
enumerate
and concat
represent Stream
versions of the same-named
quiver.iterables methods.
doWhileAsync
, reduceAsync
and forEachAsync
perform async computations on
the elements of on Iterables, waiting for the computation to complete before
processing the next element.
StreamBuffer
allows for the orderly reading of elements from a stream, such
as a socket.
FutureStream
turns a Future<Stream>
into a Stream
which emits the same
events as the stream returned from the future.
StreamRouter
splits a Stream into mulltiple streams based on a set of
predicates.
CountdownTimer
is a simple countdown timer that fires events in regular
increments.
Metronome
is a self-correcting alternative to Timer.periodic
. It provides
a simple, tracking periodic stream of DateTime
events with optional anchor
time.
Cache
is a semi-persistent, asynchronously accessed, mapping of keys to
values. Caches are similar to Maps, except that the cache implementation might
store values in a remote system, so all operations are asynchronous, and caches
might have eviction policies.
MapCache
is a Cache implementation backed by a Map.
checkArgument
throws ArgumentError
if the specifed argument check expression
is false.
checkListIndex
throws RangeError
if the specified index is out of bounds.
checkNotNull
throws ArgumentError
if the specified argument is null.
checkState
throws StateError
if the specifed state check expression is
false.
listsEqual
, mapsEqual
and setsEqual
check collections for equality.
LruMap
is a map that removes the least recently used item when a threshold
length is exceeded.
Multimap
is an associative collection that maps keys to collections of
values.
BiMap
is a bidirectional map and provides an inverse view, allowing
lookup of key by value.
TreeSet
is a balanced binary tree that offers a bidirectional iterator,
the ability to iterate from an arbitrary anchor, and 'nearest' search.
Optional
is a way to represent optional values without allowing null
.
firstNonNull
returns its first non-null argument.
hashObjects
, hash2
, hash3
, and hash4
generate high-quality hashCodes for
a list of objects, or 2, 3, or 4 arguments respectively.
visitDirectory
is a recursive directory lister that conditionally recurses
into sub-directories based on the result of a handler function.
concat
, count
, cycle
, enumerate
, merge
, partition
, range
, and
zip
create, transform, or combine Iterables in different ways, similar to
Python's itertools.
min
, max
, and extent
retreive the minimum and maximum elements from an
iterable.
GeneratingIterable
is an easy way to create lazy iterables that produce
elements by calling a function. A common use-case is to traverse properties in
an object graph, like the parent relationship in a tree.
InfiniteIterable
is a base class for Iterables that throws on operations that
require a finite length.
getTypeName
returns the name of a Type instance.
implements
and classImplements
determine if an instance or ClassMirror,
respectively, implement the interface represented by a Type instance. They
implement the behavior of is
for mirrors, except for generics.
getMemberMirror
searches though a ClassMirror and its class hierarchy for
a member. This makes up for the fact that ClassMirror.members
doesn't
contain members from interfaces or superclasses.
Method
wraps an InstanceMirror and Symbol to create a callable that invokes
a method on the instance. It in effect closurizes a method reflectively.
pattern.dart container utilities for work with Pattern
s and RegExp
s.
Glob
implements glob patterns that are commonly used with filesystem paths.
matchesAny
combines multiple Patterns into one, and allows for exclusions.
matchesFull
returns true if a Pattern matches an entire String.
escapeRegex
escapes special regex characters in a String so that it can be
used as a literal match inside of a RegExp.
isBlank
checks if a string is null
, empty or made of whitespace characters.
isEmpty
checks if a string is null
or empty.
isNotEmpty
checks if a string is not null
and not empty.
equalsIgnoreCase
checks if two strings are equal, ignoring case.
compareIgnoreCase
compares two strings, ignoring case.
loop
allows you to loop through characters in a string starting and ending at
arbitrary indices. Out of bounds indices allow you to wrap around the string,
supporting a number of use-cases, including:
loop('lohel', -3, 2) => 'hello'
String
's operator*
, but with better character-level
control, e.g.: loop('la ', 0, 8) => 'la la la' // no trailing space
loop('/path/to/some/file.txt', -3) => 'txt'
loop('top', 3, 0) => 'pot'
Clock
provides points in time relative to the current point in time, for
example: now, 2 days ago, 4 weeks from now, etc. For tesability, use Clock
rather than other ways of accessing time, like new DateTime()
, so that you
can use a fake time function in your tests to control time.
Now
is a typedef for functions that return the current time in microseconds,
since Clock deals in DateTime which only have millisecond accuracy.
aMicrosecond
, aMillisecond
, aSecond
, aMinute
, anHour
, aDay
, and
aWeek
are unit duration constants to allow writing for example:
aDay
vs. const Duration(days: 1)
aSecond * 30
vs. const Duration(seconds: 30)
The Quiver testing libraries are intended to be used in testing code, not production code. It currently consists of fake implementations of some Quiver interfaces.
FakeAsync
enables testing of units which depend upon timers and microtasks.
It supports fake advancements of time and the microtask queue, which cause fake
timers and microtasks to be processed. A Clock
is provided from which to read
the current fake time. Faking synchronous or blocking time advancement is also
supported.
areEqualityGroups
is a matcher that supports testing operator==
and
hashCode
implementations.
assertCheckedMode
asserts the current runtime has checked mode enabled.
FakeStopwatch
is a Stopwatch that uses a provided now()
function to get the
current time.
transformNullable
to pass maybe present
values through a transformer with a nullable return value.StreamConsumer<T>
to StreamConsumer<List<T>>
. Users of
StreamBuffer<List<T>>
can simply change declarations to
StreamBuffer<T>
. In cases where the generic type is already not a list
type, inputs to the list may need to be wrapped in a list.addEntries
, get
entries
, map
, removeWhere
, update
, and updateAll
.followedBy
, and accepts the orElse
parameter on singleWhere
.operator +
,
indexWhere
, and lastIndexWhere
.addEntries
, get
entries
, removeWhere
, update
, and updateAll
.Multimap.asMap()
now includes real
implementations of get entries
and removeWhere
. This class also has
"real" implementations of addEntries
, map
, update
, and updateAll
,
which just throw an UnsupportedError
, as inserts and updates are not
allowed on map views.ListMultimap
now include real implementations of
operator +
, indexWhere
, and lastIndexWhere
.ListMultimap
and SetMultimap
now include a
real implementation of followedBy
, and accept the orElse
parameter on
singleWhere
.createTimer
and createTimerPeriodic
, which
were deprecated in 0.26.0.reverse
, which was deprecated in 0.25.0.FutureGroup
, which was deprecated in 0.25.0.InfiniteIterable.singleWhere
now throws
UnsupportedError
.LruMap
linkage is incorrectly preserved when
items are removed.Maps.mapToString
in LruMap
.@visibleForTesting
annotation in AvlTreeSet
.MultiMap
's update
stub has changed
from V update(K key, C update(C value), {C ifAbsent()})
to
C update(K key, C update(C value), {C ifAbsent()})
.Iterable
, List
, Map
,
Queue
, Set
, or Timer
now implement stubs of upcoming Dart 2.0
methods. Any class that reimplements these classes also needs new method
implementations. The classes with these breaking changes include:
HashBiMap
, DelegatingIterable
, DelegatingList
,
DelegatingMap
,DelegatingQueue
, DelegatingSet
, LinkedLruHashMap
,
TreeSet
, and AvlTreeSet
.FakeAsync
. PR
#265LinkedLruHashMap
previously introduced a loop in the internal linked list.LinkedLruHashMap
, the
recency list was not correctly re-linked.LinkedLruHashMap
was put into a state
such that the next cache eviction could cause a null-pointer exception.
Issue #385.merge
on the empty set of iterables.
PR #384.flip
. Replaced by reverse
in
0.25.0.repeat
. Deprecated in 0.25.0.
Callers should use String
's *
operator.collect
, concat
, doWhileAsync
, enumerate
,
extent
, forEachAsync
, max
, merge
, min
, reduceAsync
, and zip
are now type parameterized. Depending on the inferred value of each type
parameter, the return type of each function may change in existing code.Optional
's ==
operator now takes into account T
,
the type of the value. This changes, e.g. Optional<int>.absent()
to no
longer be equal to Optional<String>.absent()
.Cache
and MapCache
.reverse
in the strings
library. No replacement is
provided.createTimer
, createTimerPeriodic
in the async
library.
These were originally written to support FakeTimer, which is superseded
by FakeAsync.isLeapYear
, daysInMonth
, clampDayOfMonth
APIs in the
time
library.contains
to know if an association key/value exists.FakeTimer
.StreamBuffer<T>
now implements StreamConsumer<T>
as
opposed to StreamConsumer<T|List<T>>
.FutureGroup
. Use the replacement in package:async
which
requires a close()
call to trigger auto-completion when the count of
pending tasks drops to 0.repeat
in the strings
library. Use the *
operator on
the String class.flip
has been renamed reverse
.
flip
is deprecated and will be removed in the next release.enumerate
is now generic.indexOf
.nullToEmpty
, emptyToNull
.Set.difference
takes a
Set<Object>
parameter.nullToEmpty
, emptyToNull
deprecated. Removal in 0.24.0.toMap
.pad*
, trim*
string functions.streams
and async
libraries have been merged into one async
libraryOptional
now implements Iterable
and its methods are generic (using temporary syntax)isNotEmpty
and isDigit
in strings.dart
Multimap.fromIterable
TreeSearch
from class
to enum
.fake_async.dart
timers are now active while executing the callbackmicrotaskCount
, periodicTimerCount
,
nonPeriodicTimerCount
.where
of Iterable
s
returned by Multimap.Metronome
.LruMap
to quiver/collection.Glob.allMatches()
to match superclass
method signature.Pattern
returned by matchesAny()
to match
superclass method signature.padLeft
, padRight
, trimLeft
,
trimRight
will be removed in 0.22.0.FakeAsync
unit test.equalsTester
dependency on unittest
with finer-grained
dependency on matcher
.path
is now a dev dependency.toMap()
is deprecated and replaced with asMap()
. toMap()
will be removed in v0.22.0.areEqualityGroups
matcher for testing operator==
and hashCode
.toString()
on returned collections.fold
.strings
.Add this to your package's pubspec.yaml file:
dependencies:
quiver: ^2.0.1
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:quiver/async.dart';
import 'package:quiver/cache.dart';
import 'package:quiver/check.dart';
import 'package:quiver/collection.dart';
import 'package:quiver/core.dart';
import 'package:quiver/io.dart';
import 'package:quiver/iterables.dart';
import 'package:quiver/mirrors.dart';
import 'package:quiver/pattern.dart';
import 'package:quiver/strings.dart';
import 'package:quiver/testing/async.dart';
import 'package:quiver/testing/equality.dart';
import 'package:quiver/testing/runtime.dart';
import 'package:quiver/testing/time.dart';
import 'package:quiver/time.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
2.0.1 | Oct 23, 2018 |
|
|
2.0.0+1 | Jul 18, 2018 |
|
|
2.0.0 | Jul 18, 2018 |
|
|
1.0.0 | Jul 18, 2018 |
|
|
0.29.0+2 | Jul 19, 2018 |
|
|
0.29.0+1 | Mar 29, 2018 |
|
|
0.29.0 | Mar 29, 2018 |
|
|
0.28.2 | Mar 24, 2018 |
|
|
0.28.1 | Mar 22, 2018 |
|
|
0.28.0 | Jan 20, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
97
|
Health:
Code health derived from static analysis.
[more]
|
77
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
70
|
Overall:
Weighted score of the above.
[more]
|
86
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: other
Platform components identified in package:
io
,mirrors
.
Fix lib/src/collection/treeset.dart
. (-6.78 points)
Analysis of lib/src/collection/treeset.dart
reported 14 hints, including:
line 48 col 21: Use =
to separate a named parameter from its default value.
line 48 col 44: Use =
to separate a named parameter from its default value.
line 52 col 48: Use =
to separate a named parameter from its default value.
line 667 col 48: Use =
to separate a named parameter from its default value.
line 676 col 25: Use =
to separate a named parameter from its default value.
Fix lib/src/time/clock.dart
. (-5.84 points)
Analysis of lib/src/time/clock.dart
reported 12 hints, including:
line 59 col 20: Use =
to separate a named parameter from its default value.
line 60 col 20: Use =
to separate a named parameter from its default value.
line 61 col 22: Use =
to separate a named parameter from its default value.
line 62 col 22: Use =
to separate a named parameter from its default value.
line 63 col 27: Use =
to separate a named parameter from its default value.
Fix lib/src/collection/multimap.dart
. (-1.99 points)
Analysis of lib/src/collection/multimap.dart
reported 4 hints:
line 510 col 32: Use =
to separate a named parameter from its default value.
line 594 col 3: Avoid return types on setters.
line 630 col 3: Avoid return types on setters.
line 646 col 3: Avoid return types on setters.
Fix additional 13 files with analysis or formatting issues. (-10.47 points)
Additional issues in the following files:
lib/testing/src/async/fake_async.dart
(4 hints)lib/src/async/metronome.dart
(3 hints)lib/src/collection/delegates/list.dart
(3 hints)lib/src/async/stream_buffer.dart
(2 hints)lib/io.dart
(1 hint)lib/src/async/future_stream.dart
(1 hint)lib/src/async/iteration.dart
(1 hint)lib/src/collection/delegates/iterable.dart
(1 hint)lib/src/collection/lru_map.dart
(1 hint)lib/src/iterables/infinite_iterable.dart
(1 hint)lib/src/iterables/merge.dart
(1 hint)lib/strings.dart
(1 hint)lib/testing/src/runtime/checked_mode.dart
(1 hint)The package description is too short. (-20 points)
Add more detail to the description
field of pubspec.yaml
. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Maintain an example. (-10 points)
Create a short demo in the example/
directory to show how to use this package.
Common filename patterns include main.dart
, example.dart
, and quiver.dart
. Packages with multiple examples should provide example/README.md
.
For more information see the pub package layout conventions.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.61 <3.0.0 | ||
matcher | >=0.10.0 <0.13.0 | 0.12.4 | |
meta | >=1.0.0 <2.0.0 | 1.1.7 | |
Transitive dependencies | |||
stack_trace | 1.9.3 | ||
Dev dependencies | |||
path | >=1.0.0 <2.0.0 | 1.6.2 | |
test | >=1.2.0 <2.0.0 |