all files / Github/diagram-js/lib/util/ Removal.js

71.43% Statements 5/7
50% Branches 2/4
100% Functions 1/1
71.43% Lines 5/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                    2018×       2018×           2018× 250×     2018×    
/**
 * Remove from the beginning of a collection until it is empty.
 *
 * This is a null-safe operation that ensures elements
 * are being removed from the given collection until the
 * collection is empty.
 *
 * The implementation deals with the fact that a remove operation
 * may touch, i.e. remove multiple elements in the collection
 * at a time.
 *
 * @param {Array<Object>} [collection]
 * @param {Function} removeFn
 *
 * @return {Array<Object>} the cleared collection
 */
export function saveClear(collection, removeFn) {
 
  Iif (typeof removeFn !== 'function') {
    throw new Error('removeFn iterator must be a function');
  }
 
  Iif (!collection) {
    return;
  }
 
  var e;
 
  while ((e = collection[0])) {
    removeFn(e);
  }
 
  return collection;
}