Skip to content

Commit

Permalink
improve: TaggedUnion .is is now S.is, isA, is the old is
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Nov 29, 2024
1 parent 8f14c99 commit fe7783b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-queens-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect-app": minor
---

improve: TaggedUnion .is is now S.is, isA, is the old is
12 changes: 10 additions & 2 deletions packages/effect-app/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,23 @@ export const tags = <
>
export const ExtendTaggedUnion = <A extends { _tag: string }, I, R>(
schema: S.Schema<A, I, R>
) => extendM(schema, (_) => ({ is: makeIs(_), isAnyOf: makeIsAnyOf(_) /*, map: taggedUnionMap(a) */ }))
) =>
extendM(schema, (_) => ({ is: S.is(schema), isA: makeIs(_), isAnyOf: makeIsAnyOf(_) /*, map: taggedUnionMap(a) */ }))

export const TaggedUnion = <
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Members extends SchemaAST.Members<S.Schema.Any & { fields: { _tag: S.tag<any> } }>
>(...a: Members) =>
pipe(
S.Union(...a),
(_) => extendM(_, (_) => ({ is: makeIs(_), isAnyOf: makeIsAnyOf(_), tagMap: taggedUnionMap(a), tags: tags(a) }))
(_) =>
extendM(_, (_) => ({
is: S.is(_),
isA: makeIs(_),
isAnyOf: makeIsAnyOf(_),
tagMap: taggedUnionMap(a),
tags: tags(a)
}))
)

export type PhoneNumber = PhoneNumberT

0 comments on commit fe7783b

Please sign in to comment.