MCPcopy Create free account
hub / github.com/Effect-TS/effect / splitIndexInKeys

Function splitIndexInKeys

packages/effect/src/internal/configProvider.ts:677–696  ·  view source on GitHub ↗
(
  map: Map<string, string>,
  unmakePathString: (str: string) => ReadonlyArray<string>,
  makePathString: (chunk: ReadonlyArray<string>) => string
)

Source from the content-addressed store, hash-verified

675}
676
677const splitIndexInKeys = (
678 map: Map<string, string>,
679 unmakePathString: (str: string) => ReadonlyArray<string>,
680 makePathString: (chunk: ReadonlyArray<string>) => string
681): Map<string, string> => {
682 const newMap: Map<string, string> = new Map()
683 for (const [pathString, value] of map) {
684 const keyWithIndex = pipe(
685 unmakePathString(pathString),
686 Arr.flatMap((key) =>
687 Option.match(splitIndexFrom(key), {
688 onNone: () => Arr.of(key),
689 onSome: ([key, index]) => Arr.make(key, `[${index}]`)
690 })
691 )
692 )
693 newMap.set(makePathString(keyWithIndex), value)
694 }
695 return newMap
696}
697
698const splitIndexFrom = (key: string): Option.Option<[string, number]> => {
699 const match = key.match(STR_INDEX_REGEX)

Callers 1

fromMapFunction · 0.85

Calls 7

unmakePathStringFunction · 0.85
splitIndexFromFunction · 0.85
makePathStringFunction · 0.85
pipeFunction · 0.70
ofMethod · 0.65
makeMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected