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

Function Option

repos/effect/packages/effect/src/Schema.ts:8486–8547  ·  view source on GitHub ↗
(value: A)

Source from the content-addressed store, hash-verified

8484 * for constructive uniqueness using Effect equality.
8485 *
8486 * @category validation
8487 * @since 4.0.0
8488 */
8489export function isUnique<T>(annotations?: Annotations.Filter) {
8490 return makeFilter<ReadonlyArray<T>>(
8491 (input) => Arr.dedupe(input).length === input.length,
8492 {
8493 expected: "an array with unique items",
8494 representation: {
8495 id: "effect/schema/isUnique",
8496 payload: null
8497 },
8498 toJsonSchema: () => ({ uniqueItems: true }),
8499 toCode: () => ({ runtime: "Schema.isUnique()" }),
8500 arbitraryConstraint: {
8501 uniqueBy: identity
8502 },
8503 ...annotations
8504 }
8505 )
8506}
8507/**
8508 * Validates that all first elements in an array of key-value tuples are unique according to Effect equality.
8509 *
8510 * **Details**
8511 *
8512 * Arbitrary:
8513 * During arbitrary generation, this projects each entry to its key for constructive uniqueness.
8514 *
8515 * JSON Schema:
8516 * JSON Schema has no equivalent constraint, so this check is omitted from generated documents.
8517 *
8518 * @see {@link isUnique} for validating uniqueness of complete array elements
8519 * @category validation
8520 * @since 4.0.0
8521 */
8522export function isUniqueKey<Key, Value>(annotations?: Annotations.Filter) {
8523 return makeFilter<ReadonlyArray<readonly [Key, Value]>>(
8524 (input) => Arr.dedupe(input.map(([key]) => key)).length === input.length,
8525 {
8526 expected: "an array with unique keys",
8527 representation: {
8528 id: "effect/schema/isUniqueKey",
8529 payload: null
8530 },
8531 toCode: () => ({ runtime: "Schema.isUniqueKey()" }),
8532 arbitraryConstraint: {
8533 uniqueBy: (entry: readonly [Key, Value]) => entry[0]
8534 },
8535 ...annotations
8536 }
8537 )
8538}
8539/**
8540 * Type-level representation of {@link NonEmptyString}.
8541 *
8542 * @category models
8543 * @since 3.10.0

Callers 6

OptionFromNullOrFunction · 0.70
OptionFromUndefinedOrFunction · 0.70
OptionFromNullishOrFunction · 0.70
OptionFromOptionalKeyFunction · 0.70
OptionFromOptionalFunction · 0.70
OptionFromOptionalNullOrFunction · 0.70

Calls 12

withRecursionFunction · 0.85
someMethod · 0.80
declareConstructorFunction · 0.70
linkFunction · 0.70
UnionFunction · 0.70
StructFunction · 0.70
LiteralFunction · 0.70
valueFunction · 0.70
makeFunction · 0.70
transformMethod · 0.65
mapMethod · 0.65
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…