{"version":3,"file":"arrayUtils.mjs","sources":["../../../../../../../core/src/utils/arrayUtils.ts"],"sourcesContent":["/**\n * Moves the first item that matches the predicate to the front of the array.\n * Returns a tuple of [reorderedArray, foundMatch] where foundMatch indicates\n * whether a matching item was found and moved.\n *\n * Note: Returns false if the array has only one item, but does return true even if the\n * item is found at index 0. This is behavior matches user expectation that you can't\n * really reorder an array of length 1.\n */\nfunction moveToFront<T>(array: T[], predicate: (item: T) => boolean): [reorderedArray: T[], foundMatch: boolean] {\n  // If the array has only one item, it can't be moved so we return false\n  if (array.length <= 1) {\n    return [array, false];\n  }\n\n  const matchingIndex = array.findIndex(predicate);\n  if (matchingIndex === -1) {\n    return [array, false];\n  }\n\n  const reordered = [...array];\n  reordered.unshift(...reordered.splice(matchingIndex, 1));\n  return [reordered, true];\n}\n\n// TODO: This weird structure is because export * seems to produce a type structure\n//       that consuming packages downstream had issues with. Not entirely sure why,\n//       I assume it's a TS bug that will be solved in the future?\nexport const arrayUtils = {\n  moveToFront,\n};\n"],"names":["moveToFront","array","predicate","length","matchingIndex","findIndex","reordered","unshift","splice","arrayUtils"],"mappings":"AAAA;;;;;;;;AAQC,IACD,SAASA,WAAAA,CAAeC,KAAU,EAAEC,SAA+B,EAAA;;IAEjE,IAAID,KAAAA,CAAME,MAAM,IAAI,CAAA,EAAG;QACrB,OAAO;AAACF,YAAAA,KAAAA;AAAO,YAAA;AAAM,SAAA;AACvB,IAAA;IAEA,MAAMG,aAAAA,GAAgBH,KAAAA,CAAMI,SAAS,CAACH,SAAAA,CAAAA;IACtC,IAAIE,aAAAA,KAAkB,EAAC,EAAG;QACxB,OAAO;AAACH,YAAAA,KAAAA;AAAO,YAAA;AAAM,SAAA;AACvB,IAAA;AAEA,IAAA,MAAMK,SAAAA,GAAY;AAAIL,QAAAA,GAAAA;AAAM,KAAA;AAC5BK,IAAAA,SAAAA,CAAUC,OAAO,CAAA,GAAID,SAAAA,CAAUE,MAAM,CAACJ,aAAAA,EAAe,CAAA,CAAA,CAAA;IACrD,OAAO;AAACE,QAAAA,SAAAA;AAAW,QAAA;AAAK,KAAA;AAC1B;AAEA;AACA;AACA;MACaG,UAAAA,GAAa;AACxBT,IAAAA;AACF;;;;"}