before method
Returns everything before a given input:
1, 2, 3, 3.before(3, 3) returns 1, 2.
1, 2, 3, 3.before(1) returns [].
1, 2, 3, 3.before([]) returns [].
Optional skip skips that many occurrences:
1, 2, 3, 3.before(3, skip: 1) returns 1, 2, 3.
Returns first skip elements when sub is empty:
1, 2, 3, 4.before([], skip: 3) returns 1, 2, 3.
overlap determines how occurrences are counted for skip:
1, 2, 1, 2, 1.before(1, 2, 1, skip: 1) returns the full list since there is only
one non-overlapping occurrence of 1, 2, 1, but
1, 2, 1, 2, 1.before(1, 2, 1, skip: 1, overlap: true) returns 1, 2.
If sub is present, includeInResult includes it at the end unless all occurrences are skipped:
1, 2, 3, 4, 5.before(3, 4, includeInResult: true) returns 1, 2, 3, 4.
reverse counts occurrences from right to left:
1, 2, 1.before(1, reverse: true) returns 1, 2.
Default h.symmetricDeepEquals counts occurrences by checking DeepCollectionEquality().equals in both
directions since it is normally asymmetric, but custom equalityFunction can be given that will
compare elements in original to elements in sub.
Implementation
Set<E> before(
Iterable<E> sub, {
int skip = 0,
bool overlap = false,
bool includeInResult = false,
bool reverse = false,
bool Function(E a, E b) equalityFunction = h.symmetricDeepEquals,
}) {
return h
.beforeIterable(
original: this,
sub: sub,
skip: skip,
overlap: overlap,
includeInResult: includeInResult,
reverse: reverse,
equalityFunction: equalityFunction,
)
.toSet();
}