MCPcopy Create free account
hub / github.com/effect-app/libs / ReadonlyMapFromArray

Function ReadonlyMapFromArray

packages/effect-app/src/Schema/ext.ts:311–338  ·  view source on GitHub ↗
(pair: {
  readonly key: KeySchema
  readonly value: ValueSchema
})

Source from the content-addressed store, hash-verified

309 * An annotated `S.Array` of key-value tuples that decodes to a `ReadonlyMap`.
310 */
311export const ReadonlyMapFromArray = <KeySchema extends S.Top, ValueSchema extends S.Top>(pair: {
312 readonly key: KeySchema
313 readonly value: ValueSchema
314}) => {
315 const from = S
316 .Array(S.Tuple([pair.key, pair.value]))
317 .annotate({
318 ...concurrencyUnbounded,
319 expected: "an array of key-value tuples that will be decoded as a ReadonlyMap"
320 })
321 const to = S.instanceOf(Map) as S.instanceOf<
322 ReadonlyMap<KeySchema["Type"], ValueSchema["Type"]>
323 >
324 const schema = from.pipe(
325 S.decodeTo(
326 to,
327 SchemaTransformation.transform({
328 decode: (
329 arr
330 ) => new Map(arr) as ReadonlyMap<KeySchema["Type"], ValueSchema["Type"]>,
331 encode: (
332 map
333 ) => [...map.entries()] as any // fu
334 })
335 )
336 )
337 return schema
338}
339
340/** Like the default Schema `ReadonlySet` but from Array, with default helpers. */
341export const ReadonlySet = <ValueSchema extends S.Top>(value: ValueSchema) =>

Callers 1

ReadonlyMapFunction · 0.85

Calls 3

annotateMethod · 0.65
pipeMethod · 0.65
transformMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…