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

Function pick

packages/effect/src/Context.ts:1459–1477  ·  view source on GitHub ↗
(
  ...services: S
)

Source from the content-addressed store, hash-verified

1457 * @since 2.0.0
1458 */
1459export const pick = <S extends ReadonlyArray<Key<any, any>>>(
1460 ...services: S
1461) =>
1462<Services>(self: Context<Services>): Context<Services & Service.Identifier<S[number]>> => {
1463 if (services.length <= 1) {
1464 const map = new Map<string, unknown>()
1465 if (services.length === 1) {
1466 const key = services[0].key
1467 const value = lookup(self, key)
1468 if (value !== notFound) map.set(key, value)
1469 }
1470 return makeFlat(undefined, map, (self as ContextImpl<any>).maxDepth)
1471 }
1472 const keep = new Set(services.map((key) => key.key))
1473 return withFlat(self, (map) =>
1474 map.forEach((_, key) => {
1475 if (!keep.has(key)) map.delete(key)
1476 }))
1477}
1478
1479/**
1480 * Returns a new `Context` with the specified service keys removed.

Callers

nothing calls this directly

Calls 8

makeFlatFunction · 0.85
withFlatFunction · 0.85
lookupFunction · 0.70
setMethod · 0.65
forEachMethod · 0.65
hasMethod · 0.65
deleteMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected