divideIn2 method

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

IListOf2<IList<T>> divideIn2(bool Function(T item) test) {
  List<T> first = [];
  List<T> last = [];
  for (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),
  );
}