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

Function HashSet

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

Source from the content-addressed store, hash-verified

11418 * @since 3.10.0
11419 */
11420export function HashSet<Value extends Constraint>(value: Value): HashSet<Value> {
11421 const schema = declareConstructor<
11422 HashSet_.HashSet<Value["Type"]>,
11423 HashSet_.HashSet<Value["Encoded"]>,
11424 HashSetIso<Value>
11425 >()(
11426 [value],
11427 ([value]) => {
11428 const values = ArraySchema(value)
11429 return (input, ast, options) => {
11430 if (HashSet_.isHashSet(input)) {
11431 return Effect.mapBothEager(
11432 SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
11433 {
11434 onSuccess: HashSet_.fromIterable,
11435 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
11436 }
11437 )
11438 }
11439 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11440 }
11441 },
11442 {
11443 representation: {
11444 id: "effect/schema/HashSet",
11445 payload: null
11446 },
11447 toCode: ({ typeParameters }) => ({
11448 runtime: `Schema.HashSet(${typeParameters[0].runtime})`,
11449 Type: `HashSet.HashSet<${typeParameters[0].Type}>`
11450 }),
11451 expected: "HashSet",
11452 toCodec: ([value]) =>
11453 link<HashSet_.HashSet<Value["Encoded"]>>()(
11454 ArraySchema(value),
11455 SchemaTransformation.transform({
11456 decode: HashSet_.fromIterable,
11457 encode: Arr.fromIterable
11458 })
11459 ),
11460 toArbitrary: ([value]) => (fc, ctx) =>
11461 collectionArbitrary(fc, ctx, value.arbitrary, value.terminal, HashSet_.fromIterable, Equal.equals),
11462 toEquivalence: ([value]) => Equal.makeCompareSet(value),
11463 toFormatter: ([value]) => (t) => {
11464 const size = HashSet_.size(t)
11465 if (size === 0) {
11466 return "HashSet(0) {}"
11467 }
11468 const values = globalThis.Array.from(t).sort().map((v) => `${value(v)}`)
11469 return `HashSet(${size}) { ${values.join(", ")} }`
11470 }
11471 }
11472 )
11473 return make(schema.ast, { value })
11474}
11475
11476/**
11477 * Reviver for persisted `HashSet` declarations.

Callers 1

Schema.tsFile · 0.70

Calls 10

collectionArbitraryFunction · 0.85
joinMethod · 0.80
declareConstructorFunction · 0.70
linkFunction · 0.70
valueFunction · 0.70
makeFunction · 0.70
transformMethod · 0.65
sizeMethod · 0.65
failMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected