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

Function check

packages/effect/src/Brand.ts:274–289  ·  view source on GitHub ↗
(
  ...checks: readonly [
    SchemaAST.Check<Brand.Unbranded<A>>,
    ...Array<SchemaAST.Check<Brand.Unbranded<A>>>
  ]
)

Source from the content-addressed store, hash-verified

272 * @since 4.0.0
273 */
274export function check<A extends Brand<any>>(
275 ...checks: readonly [
276 SchemaAST.Check<Brand.Unbranded<A>>,
277 ...Array<SchemaAST.Check<Brand.Unbranded<A>>>
278 ]
279): Constructor<A> {
280 const result = (input: Brand.Unbranded<A>): Result.Result<A, BrandError> => {
281 return Result.mapError(SchemaAST.runChecks(checks, input), (issue) => new BrandError(issue)) as any
282 }
283 return Object.assign((input: Brand.Unbranded<A>) => Result.getOrThrow(result(input)), {
284 option: (input: Brand.Unbranded<A>) => Option.getSuccess(result(input)),
285 result,
286 is: (input: Brand.Unbranded<A>): input is Brand.Unbranded<A> & A => Result.isSuccess(result(input)),
287 checks
288 })
289}
290
291/**
292 * Combines one or more brand constructors to form a single branded type.

Callers 2

makeFunction · 0.70
allFunction · 0.70

Calls 2

assignMethod · 0.80
resultFunction · 0.70

Tested by

no test coverage detected