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

Function ReadonlySet

packages/effect/src/Schema.ts:9496–9535  ·  view source on GitHub ↗
(value: Value)

Source from the content-addressed store, hash-verified

9494 * @since 3.10.0
9495 */
9496export function ReadonlySet<Value extends Constraint>(value: Value): $ReadonlySet<Value> {
9497 const schema = declareConstructor<
9498 globalThis.ReadonlySet<Value["Type"]>,
9499 globalThis.ReadonlySet<Value["Encoded"]>,
9500 ReadonlySetIso<Value>
9501 >()(
9502 [value],
9503 ([value]) => {
9504 const array = ArraySchema(value)
9505 return (input, ast, options) => {
9506 if (input instanceof globalThis.Set) {
9507 return Effect.mapBothEager(
9508 SchemaParser.decodeUnknownEffect(array)([...input], options),
9509 {
9510 onSuccess: (array: ReadonlyArray<Value["Type"]>) => new globalThis.Set(array),
9511 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
9512 }
9513 )
9514 }
9515 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
9516 }
9517 },
9518 {
9519 representation: {
9520 id: "effect/schema/ReadonlySet",
9521 payload: null
9522 },
9523 expected: "ReadonlySet",
9524 toCodec: ([value]) =>
9525 link<globalThis.Set<Value["Encoded"]>>()(
9526 ArraySchema(value),
9527 SchemaTransformation.transform({
9528 decode: (values) => new globalThis.Set(values),
9529 encode: (set) => [...set.values()]
9530 })
9531 )
9532 }
9533 )
9534 return make(schema.ast, { value })
9535}
9536/**
9537 * Type-level representation of {@link RegExp}.
9538 *

Callers

nothing calls this directly

Calls 5

declareConstructorFunction · 0.70
linkFunction · 0.70
makeFunction · 0.70
failMethod · 0.65
transformMethod · 0.65

Tested by

no test coverage detected