···7878};
79798080/**
8181+ * groups subsequent elements from an array based on a predicate
8282+ * @param array array to cluster
8383+ * @param predicate function to test consecutive elements with
8484+ * @returns an array of clusters, where each cluster is an array of consecutive elements that satisfy the predicate
8585+ */
8686+/*#__NO_SIDE_EFFECTS__*/
8787+export const cluster = <T>(array: T[], predicate: (a: T, b: T) => unknown): T[][] => {
8888+ const len = array.length;
8989+9090+ if (len === 0) {
9191+ return [];
9292+ }
9393+9494+ let prev = array[0];
9595+ let current = [prev];
9696+9797+ const clusters: T[][] = [current];
9898+9999+ for (let idx = 1; idx < len; idx++) {
100100+ const item = array[idx];
101101+102102+ if (predicate(prev, item)) {
103103+ current.push(item);
104104+ } else {
105105+ clusters.push(current = [item]);
106106+ }
107107+108108+ prev = item;
109109+ }
110110+111111+ return clusters;
112112+};
113113+114114+/**
81115 * returns elements present in the first array but not in the second
82116 * @param a the source array
83117 * @param b the array to compare against