IMultiSet<A> final
final class IMultiSet<A> with RIterableOnce<A>, RIterable<A>, RMultiSet<A>Annotations: @immutable
An immutable multiset (bag): a set where elements may appear multiple times.
Backed by an IMap from element to occurrence count. Access counts via occurrences; add with incl / +; remove one occurrence with excl / -.
final ms = imultiset([1, 1, 2]);
(ms + 3).occurrences; // IMap(1→2, 2→1, 3→1)
(ms - 1).occurrences; // IMap(1→1, 2→1)Mixed-in types
Available Extensions
Properties
hashCode no setter inherited
int get hashCodeThe hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from RMultiSet.
Implementation
@override
int get hashCode => MurmurHash3.unorderedHash(occurrences, 'MultiSet'.hashCode);head no setter inherited
A get headReturns the first element of this collection, or throws if it is empty.
Inherited from RIterable.
Implementation
A get head => iterator.next();headOption no setter inherited
Option<A> get headOptionReturns the first element of this collection as a Some if non-empty. If this collction is empty, None is returned.
Inherited from RIterable.
Implementation
Option<A> get headOption {
final it = iterator;
return Option.when(() => it.hasNext, () => it.next());
}init no setter override
IMultiSet<A> get initReturns all elements from this collection except the last. If this collection is empty, an empty collection is returned.
Implementation
@override
IMultiSet<A> get init => IMultiSet.from(super.init);inits no setter override
Returns an iterator of all potential tails of this collection, starting with the entire collection and ending with an empty one.
Implementation
@override
RIterator<IMultiSet<A>> get inits => super.inits.map(IMultiSet.from);isEmpty no setter inherited
bool get isEmptyWhether this collection contains no elements.
Inherited from RIterableOnce.
Implementation
bool get isEmpty => switch (knownSize) {
-1 => !iterator.hasNext,
0 => true,
_ => false,
};isNotEmpty no setter inherited
bool get isNotEmptyWhether this collection contains at least one element.
Inherited from RIterableOnce.
Implementation
bool get isNotEmpty => !isEmpty;isTraversableAgain no setter inherited
bool get isTraversableAgainWhether this collection can be traversed more than once.
Always false for a bare RIterableOnce; overridden to true by RIterable and its subtypes.
Inherited from RIterableOnce.
Implementation
bool get isTraversableAgain => false;iterator no setter inherited
RIterator<A> get iteratorReturns an RIterator over the elements of this collection.
Inherited from RMultiSet.
Implementation
@override
RIterator<A> get iterator => occurrences.iterator.flatMap((kv) => views.Fill(kv.$2, kv.$1));knownSize no setter inherited
int get knownSizeReturns the number of elements in this collection, if that number is already known. If not, -1 is returned.
Inherited from RIterableOnce.
Implementation
int get knownSize => -1;last no setter inherited
A get lastReturns the last element of this collection, or throws if it is empty.
Inherited from RIterable.
Implementation
A get last {
final it = iterator;
var lst = it.next();
while (it.hasNext) {
lst = it.next();
}
return lst;
}lastOption no setter inherited
Option<A> get lastOptionReturns the last element of this collection as a Some, or None if this collection is empty.
Inherited from RIterable.
Implementation
Option<A> get lastOption {
if (isEmpty) {
return none();
} else {
final it = iterator;
var last = it.next();
while (it.hasNext) {
last = it.next();
}
return Some(last);
}
}nonEmpty no setter inherited
bool get nonEmptyWhether this collection contains at least one element.
Inherited from RIterableOnce.
Implementation
bool get nonEmpty => !isEmpty;occurrences no setter override
RMap<A, int> get occurrencesThe underlying map from each distinct element to its occurrence count.
Implementation
@override
RMap<A, int> get occurrences => _elems;runtimeType no setter inherited
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;size no setter inherited
int get sizeReturns the number of elements in this collection.
Inherited from RIterableOnce.
Implementation
int get size {
if (knownSize >= 0) {
return knownSize;
} else {
final it = iterator;
var len = 0;
while (it.hasNext) {
len += 1;
it.next();
}
return len;
}
}tail no setter override
IMultiSet<A> get tailReturns a new collection with the first element removed. If this collection is empty, an empty collection is returned.
Implementation
@override
IMultiSet<A> get tail => IMultiSet.from(super.tail);tails no setter override
Returns an iterator of all potential tails of this collection, starting with the entire collection and ending with an empty one.
Implementation
@override
RIterator<IMultiSet<A>> get tails => super.tails.map(IMultiSet.from);Methods
collect() override
Returns a new collection by applying f to each element an only keeping results of type Some.
Implementation
@override
IMultiSet<B> collect<B>(Function1<A, Option<B>> f) => IMultiSet.from(super.collect(f));collectFirst() inherited
Applies f to each element of this collection, returning the first element that results in a Some, if any.
Inherited from RIterableOnce.
Implementation
Option<B> collectFirst<B>(Function1<A, Option<B>> f) {
final it = iterator;
while (it.hasNext) {
final x = f(it.next());
if (x.isDefined) return x;
}
return none();
}collectOccurances() inherited
Applies f to each (element, count) pair, keeping only Some results.
Inherited from RMultiSet.
Implementation
RMultiSet<B> collectOccurances<B>(Function1<(A, int), Option<(B, int)>> f) => flatMapOccurences(
(kvs) => f(kvs).fold(
() => const views.Empty(),
(res) => views.Single(res),
),
);concat() override
IMultiSet<A> concat(RIterableOnce<A> suffix)Returns a copy of this collection, with elems added to the end.
Implementation
@override
IMultiSet<A> concat(RIterableOnce<A> suffix) => IMultiSet.from(iterator.concat(suffix.iterator));concatOccurences() override
Returns a new multiset formed by adding all (element, count) pairs from that.
Implementation
@override
IMultiSet<A> concatOccurences(RIterable<(A, int)> that) => IMultiSet.fromOccurences(that);contains() inherited
bool contains(A elem)Returns true if elem appears at least once in this multiset.
Inherited from RMultiSet.
Implementation
bool contains(A elem) => occurrences.contains(elem);copyToArray() inherited
int copyToArray(Array<A> xs, [int start = 0, int? n])Copies elements into xs starting at start, writing at most n elements (or all remaining capacity when n is omitted).
Returns the number of elements actually copied.
Inherited from RIterableOnce.
Implementation
int copyToArray(Array<A> xs, [int start = 0, int? n]) {
final it = iterator;
final end = start + min(n ?? Integer.maxValue, xs.length - start);
var i = start;
while (i < end && it.hasNext) {
xs[i] = it.next();
i += 1;
}
return i - start;
}corresponds() inherited
bool corresponds<B>(RIterable<B> that, bool Function(A, B) p)Returns true if this collection has the same size as that and each corresponding element from this and that satisfies the given predicate p.
Inherited from RIterableOnce.
Implementation
bool corresponds<B>(
covariant RIterable<B> that,
Function2<A, B, bool> p,
) {
final a = iterator;
final b = that.iterator;
while (a.hasNext && b.hasNext) {
if (!p(a.next(), b.next())) return false;
}
return !a.hasNext && !b.hasNext;
}count() inherited
int count(bool Function(A) p)Return the number of elements in this collection that satisfy the given predicate.
Inherited from RIterableOnce.
Implementation
int count(Function1<A, bool> p) {
var res = 0;
final it = iterator;
while (it.hasNext) {
if (p(it.next())) res += 1;
}
return res;
}drop() override
IMultiSet<A> drop(int n)Returns a new collection with the first n elements removed.
Implementation
@override
IMultiSet<A> drop(int n) => IMultiSet.from(super.drop(n));dropRight() override
IMultiSet<A> dropRight(int n)Return a new collection with the last n elements removed.
Implementation
@override
IMultiSet<A> dropRight(int n) => IMultiSet.from(super.dropRight(n));dropWhile() override
IMultiSet<A> dropWhile(bool Function(A) p)Returns a new collection with leading elements satisfying p removed.
Implementation
@override
IMultiSet<A> dropWhile(Function1<A, bool> p) => IMultiSet.from(super.dropWhile(p));excl()
IMultiSet<A> excl(A elem)Returns a new multiset with one fewer occurrence of elem.
Removes the key entirely when its count would drop to zero.
Implementation
IMultiSet<A> excl(A elem) => IMultiSet._(
_elems.updatedWith(
elem,
(n) => n.fold(
() => none(),
(n) => n > 1 ? Some(n - 1) : none(),
),
),
);exists() inherited
bool exists(bool Function(A) p)Returns true if any element of this collection satisfies the given predicate, false if no elements satisfy it.
Inherited from RIterableOnce.
Implementation
bool exists(Function1<A, bool> p) {
var res = false;
final it = iterator;
while (!res && it.hasNext) {
res = p(it.next());
}
return res;
}filter() override
IMultiSet<A> filter(bool Function(A) p)Returns a new collection containing only elements that satisfy p.
Implementation
@override
IMultiSet<A> filter(Function1<A, bool> p) => IMultiSet.from(super.filter(p));filterNot() override
IMultiSet<A> filterNot(bool Function(A) p)Returns a new collection containing only elements that do not satisfy p.
Implementation
@override
IMultiSet<A> filterNot(Function1<A, bool> p) => IMultiSet.from(super.filterNot(p));filterOccurences() override
IMultiSet<A> filterOccurences(bool Function(Record) p)Returns a new multiset keeping only the (element, count) pairs that satisfy p.
Implementation
@override
IMultiSet<A> filterOccurences(Function1<(A, int), bool> p) =>
IMultiSet.fromOccurences(views.Filter(occurrences, p, false));find() inherited
Option<A> find(bool Function(A) p)Returns the first element from this collection that satisfies the given predicate p. If no element satisfies p, None is returned.
Inherited from RIterableOnce.
Implementation
Option<A> find(Function1<A, bool> p) {
final it = iterator;
while (it.hasNext) {
final a = it.next();
if (p(a)) return Some(a);
}
return none();
}flatMap() override
IMultiSet<B> flatMap<B>(RIterableOnce<B> Function(A) f)Returns a new collection by applying f to each element and concatenating the results.
Implementation
@override
IMultiSet<B> flatMap<B>(Function1<A, RIterableOnce<B>> f) => IMultiSet.from(super.flatMap(f));flatMapOccurences() override
IMultiSet<B> flatMapOccurences<B>(RIterableOnce<Record> Function(Record) f)Returns a new multiset by applying f to each (element, count) pair and concatenating the resulting occurrence sequences.
Implementation
@override
IMultiSet<B> flatMapOccurences<B>(
Function1<(A, int), RIterableOnce<(B, int)>> f,
) => IMultiSet.fromOccurences(views.FlatMap(occurrences, f));fold() inherited
A fold(A init, A Function(A, A) op)Alias for foldLeft with a same-type accumulator.
Inherited from RIterable.
Implementation
A fold(A init, Function2<A, A, A> op) => foldLeft(init, op);foldLeft() inherited
B foldLeft<B>(B z, B Function(B, A) op)Returns a summary value by applying op to all elements of this collection, moving from left to right. The fold uses a seed value of z.
Inherited from RIterableOnce.
Implementation
B foldLeft<B>(B z, Function2<B, A, B> op) {
var result = z;
final it = iterator;
while (it.hasNext) {
result = op(result, it.next());
}
return result;
}foldRight() inherited
B foldRight<B>(B z, B Function(A, B) op)Returns a summary value by applying op to all elements of this collection, moving from right to left. The fold uses a seed value of z.
Inherited from RIterableOnce.
Implementation
B foldRight<B>(B z, Function2<A, B, B> op) => _reversed().foldLeft(z, (b, a) => op(a, b));forall() inherited
bool forall(bool Function(A) p)Returns true if all elements of this collection satisfy the given predicate, false if any elements do not.
Inherited from RIterableOnce.
Implementation
bool forall(Function1<A, bool> p) {
var res = true;
final it = iterator;
while (res && it.hasNext) {
res = p(it.next());
}
return res;
}foreach() inherited
void foreach<U>(U Function(A) f)Applies f to each element of this collection, discarding any resulting values.
Inherited from RIterableOnce.
Implementation
void foreach<U>(Function1<A, U> f) {
final it = iterator;
while (it.hasNext) {
f(it.next());
}
}get() inherited
int get(A elem)Returns the number of times elem appears in this multiset, or 0 if it is absent.
Inherited from RMultiSet.
Implementation
int get(A elem) => occurrences.getOrElse(elem, () => 0);groupBy() override
Partitions all elements of this collection by applying f to each element and accumulating duplicate keys in the returned IMap.
Implementation
@override
IMap<K, IMultiSet<A>> groupBy<K>(Function1<A, K> f) => super.groupBy(f).mapValues(IMultiSet.from);grouped() override
Returns a new iterator where each element is a collection of size elements from the original collection. The last element may contain less than size elements.
Implementation
@override
RIterator<IMultiSet<A>> grouped(int size) => super.grouped(size).map(IMultiSet.from);groupMap() override
Creates a new map by generating a key-value pair for each elements of this collection using key and f. Any elements that generate the same key will have the resulting values accumulated in the returned map.
Implementation
@override
IMap<K, IMultiSet<B>> groupMap<K, B>(
Function1<A, K> key,
Function1<A, B> f,
) => super.groupMap(key, f).mapValues(IMultiSet.from);groupMapReduce() inherited
IMap<K, B> groupMapReduce<K, B>(
K Function(A) key,
B Function(A) f,
B Function(B, B) reduce,
)Partitions all elements of this collection by applying key to each element. Additionally f is applied to each element to generate a value. If multiple values are generating for the same key, those values will be combined using reduce.
Inherited from RIterable.
Implementation
IMap<K, B> groupMapReduce<K, B>(
Function1<A, K> key,
Function1<A, B> f,
Function2<B, B, B> reduce,
) {
final m = <K, B>{};
foreach((elem) {
m.update(key(elem), (b) => reduce(b, f(elem)), ifAbsent: () => f(elem));
});
return IMap.fromDart(m);
}incl()
IMultiSet<A> incl(A elem)Returns a new multiset with one additional occurrence of elem.
Implementation
IMultiSet<A> incl(A elem) =>
IMultiSet._(_elems.updatedWith(elem, (n) => Some(n.fold(() => 1, (n) => n + 1))));map() override
IMultiSet<B> map<B>(B Function(A) f)Returns a new collection by applying f to each element.
Implementation
@override
IMultiSet<B> map<B>(Function1<A, B> f) => IMultiSet.from(iterator.map(f));mapOccurences() override
IMultiSet<B> mapOccurences<B>(Record Function(Record) f)Returns a new multiset by applying f to each (element, count) pair.
Implementation
@override
IMultiSet<B> mapOccurences<B>(Function1<(A, int), (B, int)> f) =>
IMultiSet.fromOccurences(views.Map<(A, int), (B, int)>(occurrences, f));maxByOption() inherited
Finds the largest element in this collection by applying f to each element and using the given Order to find the greatest.
If this collection is empty, None is returned.
Inherited from RIterableOnce.
Implementation
Option<A> maxByOption<B>(Function1<A, B> f, Order<B> order) => _minMaxByOption(f, order.max);maxOption() inherited
Finds the largest element in this collection according to the given Order.
If this collection is empty, None is returned.
Inherited from RIterableOnce.
Implementation
Option<A> maxOption(Order<A> order) => switch (knownSize) {
0 => none(),
_ => _reduceOptionIterator(iterator, order.max),
};minByOption() inherited
Finds the smallest element in this collection by applying f to each element and using the given Order to find the greatest.
If this collection is empty, None is returned.
Inherited from RIterableOnce.
Implementation
Option<A> minByOption<B>(Function1<A, B> f, Order<B> order) => _minMaxByOption(f, order.min);minOption() inherited
Finds the largest element in this collection according to the given Order.
If this collection is empty, None is returned.
Inherited from RIterableOnce.
Implementation
Option<A> minOption(Order<A> order) => switch (knownSize) {
0 => none(),
_ => _reduceOptionIterator(iterator, order.min),
};mkString() inherited
String mkString({String? start, String? sep, String? end})Returns a String by using each elements toString(), adding sep between each element. If start is defined, it will be prepended to the resulting string. If end is defined, it will be appended to the resulting string.
Inherited from RIterableOnce.
Implementation
String mkString({String? start, String? sep, String? end}) {
if (knownSize == 0) {
return '${start ?? ""}${end ?? ""}';
} else {
return _mkStringImpl(StringBuffer(), start ?? '', sep ?? '', end ?? '');
}
}noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);partition() override
Record partition(bool Function(A) p)Returns 2 collections as a tuple where the first tuple element will be a collection of elements that satisfy the given predicate p. The second item of the returned tuple will be elements that do not satisfy p.
Implementation
@override
(IMultiSet<A>, IMultiSet<A>) partition(Function1<A, bool> p) {
final (first, second) = super.partition(p);
return (IMultiSet.from(first), IMultiSet.from(second));
}partitionMap() override
Record partitionMap<A1, A2>(Either<A1, A2> Function(A) f)Applies f to each element of this collection and returns a separate collection for all applications resulting in a Left and Right respectively.
Implementation
@override
(RIterable<A1>, RIterable<A2>) partitionMap<A1, A2>(
Function1<A, Either<A1, A2>> f,
) {
final (first, second) = super.partitionMap(f);
return (IMultiSet.from(first), IMultiSet.from(second));
}reduce() inherited
A reduce(A Function(A, A) op)Reduces this collection to a single value by applying op left to right.
Throws if the collection is empty.
Inherited from RIterableOnce.
Implementation
A reduce(Function2<A, A, A> op) => reduceLeft(op);reduceLeft() inherited
A reduceLeft(A Function(A, A) op)Reduces from left to right. Throws if empty.
Inherited from RIterableOnce.
Implementation
A reduceLeft(Function2<A, A, A> op) => switch (this) {
final IndexedSeq<A> seq when seq.length > 0 => _foldl(seq, 1, seq[0], op),
_ when knownSize == 0 => throw UnsupportedError('empty.reduceLeft'),
_ => _reduceLeftIterator(() => throw UnsupportedError('empty.reduceLeft'), op),
};reduceLeftOption() inherited
Option<A> reduceLeftOption(A Function(A, A) op)Returns a summary values of all elements of this collection by applying f to each element, moving left to right.
If this collection is empty, None will be returned.
Inherited from RIterableOnce.
Implementation
Option<A> reduceLeftOption(Function2<A, A, A> op) => switch (knownSize) {
0 => none(),
_ => _reduceOptionIterator(iterator, op),
};reduceOption() inherited
Option<A> reduceOption(A Function(A, A) op)Returns a summary values of all elements of this collection by applying f to each element, moving left to right.
If this collection is empty, None will be returned.
Inherited from RIterableOnce.
Implementation
Option<A> reduceOption(Function2<A, A, A> op) => reduceLeftOption(op);reduceRight() inherited
A reduceRight(A Function(A, A) op)Reduces from right to left. Throws if empty.
Inherited from RIterableOnce.
Implementation
A reduceRight(Function2<A, A, A> op) => switch (this) {
final IndexedSeq<A> seq when seq.length > 0 => _foldr(seq, op),
_ when knownSize == 0 => throw UnsupportedError('empty.reduceLeft'),
_ => _reversed().reduceLeft((x, y) => op(y, x)),
};reduceRightOption() inherited
Option<A> reduceRightOption(A Function(A, A) op)Returns a summary values of all elements of this collection by applying f to each element, moving right to left.
If this collection is empty, None will be returned.
Inherited from RIterableOnce.
Implementation
Option<A> reduceRightOption(Function2<A, A, A> op) => switch (knownSize) {
-1 => _reduceOptionIterator(_reversed().iterator, (x, y) => op(y, x)),
0 => none(),
_ => Some(reduceRight(op)),
};scan() inherited
RMultiSet<B> scan<B>(B z, B Function(B, A) op)Alias for scanLeft.
Inherited from RMultiSet.
Implementation
@override
RMultiSet<B> scan<B>(B z, Function2<B, A, B> op) => RMultiSet.from(super.scan(z, op));scanLeft() inherited
RMultiSet<B> scanLeft<B>(B z, B Function(B, A) op)Returns a new collection of running totals starting with z.
The first element of the result is z; each subsequent element is the result of applying op to the previous total and the next element.
Inherited from RMultiSet.
Implementation
@override
RMultiSet<B> scanLeft<B>(B z, Function2<B, A, B> op) => RMultiSet.from(super.scanLeft(z, op));scanRight() inherited
RMultiSet<B> scanRight<B>(B z, B Function(A, B) op)Returns a new collection of running totals starting with z, traversing from right to left.
Inherited from RMultiSet.
Implementation
@override
RMultiSet<B> scanRight<B>(B z, Function2<A, B, B> op) => RMultiSet.from(super.scanRight(z, op));slice() override
IMultiSet<A> slice(int from, int until)Returns a new collection containing elements in the range [from, until).
Implementation
@override
IMultiSet<A> slice(int from, int until) => IMultiSet.from(super.slice(from, until));sliding() override
Returns an iterator where elements are fixed size chunks of size n of the original collection. Each chunk is calculated by sliding a 'window' of size n over the original collection, moving the window step elements at a time.
Implementation
@override
RIterator<IMultiSet<A>> sliding(int size, [int step = 1]) =>
super.sliding(size, step).map(IMultiSet.from);span() override
Record span(bool Function(A) p)Returns two collections: elements before and starting from the first element that does not satisfy p.
Implementation
@override
(IMultiSet<A>, IMultiSet<A>) span(Function1<A, bool> p) {
final (first, second) = super.span(p);
return (IMultiSet.from(first), IMultiSet.from(second));
}splitAt() override
Record splitAt(int n)Returns two collections: the first n elements and the remainder.
Implementation
@override
(IMultiSet<A>, IMultiSet<A>) splitAt(int n) {
final (first, second) = super.splitAt(n);
return (IMultiSet.from(first), IMultiSet.from(second));
}take() override
IMultiSet<A> take(int n)Returns a new collection containing only the first n elements.
Implementation
@override
IMultiSet<A> take(int n) => IMultiSet.from(super.take(n));takeRight() override
IMultiSet<A> takeRight(int n)Returns a new collection with the last n elements of this collection. If n is greater than the size of this collection, the original collection is returned.
Implementation
@override
IMultiSet<A> takeRight(int n) => IMultiSet.from(super.takeRight(n));takeWhile() override
IMultiSet<A> takeWhile(bool Function(A) p)Returns a new collection of leading elements that satisfy p.
Implementation
@override
IMultiSet<A> takeWhile(Function1<A, bool> p) => IMultiSet.from(super.takeWhile(p));tapEach() override
IMultiSet<A> tapEach<U>(U Function(A) f)Applies f to each element in this collection, discarding any results and returns this collection.
Implementation
@override
IMultiSet<A> tapEach<U>(Function1<A, U> f) {
foreach(f);
return this;
}toIList() inherited
IList<A> toIList()Returns an IList with the same elements as this collection.
Inherited from RIterableOnce.
Implementation
IList<A> toIList() => IList.from(this);toIndexedSeq() inherited
IndexedSeq<A> toIndexedSeq()Returns an IndexedSeq with the same elements as this collection.
Inherited from RIterableOnce.
Implementation
IndexedSeq<A> toIndexedSeq() => IndexedSeq.from(this);toISet() inherited
ISet<A> toISet()Returns an ISet with the same elements as this collection, duplicates removed.
Inherited from RIterableOnce.
Implementation
ISet<A> toISet() => ISet.from(this);toIVector() inherited
IVector<A> toIVector()Returns an IVector with the same elements as this collection.
Inherited from RIterableOnce.
Implementation
IVector<A> toIVector() => IVector.from(this);toList() inherited
List<A> toList({bool growable = true})Returns a new List with the same elements as this collection.
Inherited from RIterableOnce.
Implementation
List<A> toList({bool growable = true}) {
if (growable) {
final it = iterator;
final res = List<A>.empty(growable: true);
while (it.hasNext) {
res.add(it.next());
}
return res;
} else {
final it = iterator;
return List.generate(size, (_) => it.next());
}
}toSeq() inherited
RSeq<A> toSeq()Returns a RSeq with the same elements as this collection.
Inherited from RIterableOnce.
Implementation
RSeq<A> toSeq() => RSeq.from(this);toString() inherited
String toString()A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Inherited from RIterable.
Implementation
@override
String toString() => 'Iterable${mkString(start: '(', sep: ', ', end: ')')}';zip() override
IMultiSet<Record> zip<B>(RIterableOnce<B> that)Returns a new collection that combines corresponding elements from this collection and that as a tuple. The length of the returned collection will be the minimum of this collections size and the size of that.
Implementation
@override
IMultiSet<(A, B)> zip<B>(RIterableOnce<B> that) => IMultiSet.from(super.zip(that));zipAll() override
IMultiSet<Record> zipAll<B>(RIterableOnce<B> that, A thisElem, B thatElem)Returns a new collection that combines corresponding elements from this collection and that as a tuple. The length of the returned collection will be the maximum of this collections size and thes size of that. If this collection is shorter than that, thisElem will be used to fill in the resulting collection. If that is shorter, thatElem will be used to will in the resulting collection.
Implementation
@override
IMultiSet<(A, B)> zipAll<B>(RIterableOnce<B> that, A thisElem, B thatElem) =>
IMultiSet.from(super.zipAll(that, thisElem, thatElem));zipWithIndex() override
IMultiSet<Record> zipWithIndex()Return a new collection with each element of this collection paired with it's respective index.
Implementation
@override
IMultiSet<(A, int)> zipWithIndex() => IMultiSet.from(super.zipWithIndex());Extension Methods
flatten() extension
RIterable<A> flatten()Concatenates all inner iterables into a single IList.
Available on RIterable<A>, provided by the RIterableNested2Ops<A> extension
Implementation
RIterable<A> flatten() {
final it = iterator;
final b = IList.builder<A>();
while (it.hasNext) {
b.addAll(it.next());
}
return b.toIList();
}product() extension
double product()Returns the product of all elements in this list
Available on RIterableOnce<A>, provided by the RIterableDoubleOps extension
Implementation
double product() {
var p = 1.0;
final it = iterator;
while (it.hasNext) {
p *= it.next();
}
return p;
}product() extension
int product()Returns the product of all elements in this list
Available on RIterableOnce<A>, provided by the RIterableIntOps extension
Implementation
int product() {
var p = 1;
final it = iterator;
while (it.hasNext) {
p *= it.next();
}
return p;
}sum() extension
double sum()Returns the sum of all elements in this list
Available on RIterableOnce<A>, provided by the RIterableDoubleOps extension
Implementation
double sum() {
var s = 0.0;
final it = iterator;
while (it.hasNext) {
s += it.next();
}
return s;
}sum() extension
int sum()Returns the sum of all elements in this list
Available on RIterableOnce<A>, provided by the RIterableIntOps extension
Implementation
int sum() {
var s = 0;
final it = iterator;
while (it.hasNext) {
s += it.next();
}
return s;
}toIMap() extension
IMap<A, B> toIMap()Creates a new IMap where element tuple element of this list is used to create a key and value respectively.
Available on RIterable<A>, provided by the RIterableTuple2Ops<A, B> extension
Implementation
IMap<A, B> toIMap() => IMap.from(this);unzip() extension
Record unzip()Splits a collection of pairs into two separate collections.
Available on RIterable<A>, provided by the RibsIterableTuple2Ops<A, B> extension
Implementation
(RIterable<A>, RIterable<B>) unzip() => (
views.Map(this, (a) => a.$1),
views.Map(this, (a) => a.$2),
);Operators
operator +()
IMultiSet<A> operator +(A elem)Returns a new multiset with one additional occurrence of elem.
Implementation
IMultiSet<A> operator +(A elem) => incl(elem);operator -()
IMultiSet<A> operator -(A elem)Returns a new multiset with one fewer occurrence of elem.
Has no effect if elem is not present.
Implementation
IMultiSet<A> operator -(A elem) => excl(elem);operator ==() inherited
bool operator ==(Object other)The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from RMultiSet.
Implementation
@override
bool operator ==(Object other) =>
identical(this, other) ||
switch (other) {
final RMultiSet<A> that =>
size == that.size && occurrences.forall((kv) => that.get(kv.$1) == kv.$2),
_ => false,
};Static Methods
empty() override
IMultiSet<A> empty<A>()Returns an empty IMultiSet.
Implementation
static IMultiSet<A> empty<A>() => IMultiSet._(IMap.empty());from() override
IMultiSet<A> from<A>(RIterableOnce<A> elems)Creates an IMultiSet from any RIterableOnce.
Returns elems directly when it is already an IMultiSet.
Implementation
static IMultiSet<A> from<A>(RIterableOnce<A> elems) => switch (elems) {
final IMultiSet<A> ms => ms,
_ => IMultiSet._(elems.toIList().groupMapReduce(identity, (_) => 1, (a, b) => a + b)),
};fromDartIterable() override
IMultiSet<A> fromDartIterable<A>(Iterable<A> elems)Creates an IMultiSet from a Dart Iterable.
Implementation
static IMultiSet<A> fromDartIterable<A>(Iterable<A> elems) =>
IMultiSet.from(RIterator.fromDart(elems.iterator));fromOccurences() override
IMultiSet<A> fromOccurences<A>(RIterableOnce<Record> elems)Creates an IMultiSet from an iterable of (element, count) pairs.
Implementation
static IMultiSet<A> fromOccurences<A>(RIterableOnce<(A, int)> elems) => switch (elems) {
final IMultiSet<A> ms => ms,
_ => from(elems.flatMap((occ) => views.Fill(occ.$2, occ.$1))),
};