MCPcopy Index your code
hub / github.com/Effect-TS/effect / splitIndexInKeys

Function splitIndexInKeys

packages/effect/src/internal/configProvider.ts:656–675  ·  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

654}
655
656const splitIndexInKeys = (
657 map: Map<string, string>,
658 unmakePathString: (str: string) => ReadonlyArray<string>,
659 makePathString: (chunk: ReadonlyArray<string>) => string
660): Map<string, string> => {
661 const newMap: Map<string, string> = new Map()
662 for (const [pathString, value] of map) {
663 const keyWithIndex = pipe(
664 unmakePathString(pathString),
665 Arr.flatMap((key) =>
666 Option.match(splitIndexFrom(key), {
667 onNone: () => Arr.of(key),
668 onSome: ([key, index]) => Arr.make(key, `[${index}]`)
669 })
670 )
671 )
672 newMap.set(makePathString(keyWithIndex), value)
673 }
674 return newMap
675}
676
677const splitIndexFrom = (key: string): Option.Option<[string, number]> => {
678 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…