613562f504
Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
18 lines
497 B
TypeScript
18 lines
497 B
TypeScript
import { Schema } from "effect"
|
|
|
|
/**
|
|
* Attach static methods to a schema object. Designed to be used with `.pipe()`:
|
|
*
|
|
* @example
|
|
* export const Foo = fooSchema.pipe(
|
|
* withStatics((schema) => ({
|
|
* zero: schema.makeUnsafe(0),
|
|
* from: Schema.decodeUnknownOption(schema),
|
|
* }))
|
|
* )
|
|
*/
|
|
export const withStatics =
|
|
<S extends object, M extends Record<string, unknown>>(methods: (schema: S) => M) =>
|
|
(schema: S): S & M =>
|
|
Object.assign(schema, methods(schema))
|