(pair: {
readonly key: KeySchema
readonly value: ValueSchema
})
| 309 | * An annotated `S.Array` of key-value tuples that decodes to a `ReadonlyMap`. |
| 310 | */ |
| 311 | export 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. */ |
| 341 | export const ReadonlySet = <ValueSchema extends S.Top>(value: ValueSchema) => |
no test coverage detected
searching dependent graphs…