before method

Queue<E> before(
  1. Iterable<E> sub, {
  2. int skip = 0,
  3. bool overlap = false,
  4. bool includeInResult = false,
  5. bool reverse = false,
  6. bool equalityFunction(
    1. E a,
    2. E b
    ) = h.symmetricDeepEquals,
})

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

Queue<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,
      )
      .toQueue();
}