MCPcopy
hub / github.com/Effect-TS/effect / fromBrand

Function fromBrand

packages/effect/src/Schema.ts:1113–1136  ·  view source on GitHub ↗
(
  constructor: Brand.Constructor<C>,
  annotations?: Annotations.Filter<C, A>
)

Source from the content-addressed store, hash-verified

1111 * @since 3.10.0
1112 */
1113export const fromBrand = <C extends Brand<string | symbol>, A extends Brand.Unbranded<C>>(
1114 constructor: Brand.Constructor<C>,
1115 annotations?: Annotations.Filter<C, A>
1116) =>
1117<I, R>(self: Schema<A, I, R>): BrandSchema<A & C, I, R> => {
1118 const out = makeBrandClass(
1119 self,
1120 new AST.Refinement(
1121 self.ast,
1122 function predicate(a: A, _: ParseOptions, ast: AST.AST): option_.Option<ParseResult.ParseIssue> {
1123 const either = constructor.either(a)
1124 return either_.isLeft(either) ?
1125 option_.some(new ParseResult.Type(ast, a, either.left.map((v) => v.message).join(", "))) :
1126 option_.none()
1127 },
1128 toASTAnnotations({
1129 schemaId: BrandSchemaId,
1130 [BrandSchemaId]: { constructor },
1131 ...annotations
1132 })
1133 )
1134 )
1135 return out as any
1136}
1137
1138/**
1139 * @category schema id

Callers

nothing calls this directly

Calls 5

makeBrandClassFunction · 0.85
toASTAnnotationsFunction · 0.85
eitherMethod · 0.80
joinMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…