divideIn2 method

  1. @useResult
IListOf2<IList<T>> divideIn2(
  1. bool test(
    1. T item
    )
)

Divides the list into two. The first one contains all items which satisfy the provided test. The last one contains all the other items. The relative order of the items will be maintained.

See also: IListOf2

Implementation

@useResult
IListOf2<IList<T>> divideIn2(bool Function(T item) test) {
  final List<T> first = [];
  final List<T> last = [];
  for (final T item in this) {
    if (test(item))
      first.add(item);
    else
      last.add(item);
  }
  return IListOf2(
    IList._unsafeFromList(first, config: config),
    IList._unsafeFromList(last, config: config),
  );
}