insertWith<A> method

Iterable<T> insertWith<A>(
  1. A insert(
    1. T instance
    ),
  2. Order<A> order,
  3. T element
)

Insert element into the list at the first position where it is less than or equal to the next element based on order of an object of type A extracted from element using insert.

Note: The element is added before an equal element already in the Iterable.

Implementation

Iterable<T> insertWith<A>(
        A Function(T instance) insert, Order<A> order, T element) =>
    isEmpty
        ? [element]
        : order.compare(insert(element), insert(first)) > 0
            ? [first, ...drop(1).insertWith(insert, order, element)]
            : [element, first, ...drop(1)];