Skip to content

Commit 547df94

Browse files
authored
feat(core): adds t.inline combinator that lifts a guard into a schema (#38)
* feat(core): adds `t.inline` combinator for lifting a guard into a schema * chore: commits changeset
1 parent f873c28 commit 547df94

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.changeset/proud-bikes-return.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@traversable/schema-core": patch
3+
---
4+
5+
feat(core): adds `t.inline` combinator for lifting a guard into a schema

packages/schema-core/src/core.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export declare namespace t {
125125

126126
export declare namespace t {
127127
type _ = unknown
128-
interface Inline<T> { readonly _type: T, tag: URI.inline }
128+
interface Inline<T> extends Guard<T> { readonly _type: T, tag: URI.inline }
129129
interface Top { readonly _type: unknown, tag: URI.top, }
130130
interface Bottom { readonly _type: never, tag: URI.bottom, }
131131
interface InvalidSchema<_Err> extends TypeError<''>, t.Never { }
@@ -154,6 +154,12 @@ export namespace t {
154154
export const Boolean: t.Boolean = Object_assign((_: _) => typeof _ === 'boolean', <t.Boolean>AST.boolean)
155155
export const Number: t.Number = Object_assign((_: _) => typeof _ === 'number', <t.Number>AST.number)
156156
export const String: t.String = Object_assign((_: _) => typeof _ === 'string', <t.String>AST.string)
157+
export function Inline<S>(guard: Guard<S>): t.Inline<S>
158+
export function Inline<S>(guard: Guard<S> & { tag?: URI.inline }): Guard<S> & { tag?: URI.inline } {
159+
guard.tag = URI.inline
160+
return guard
161+
}
162+
157163
export type Leaf = typeof Leaves[number]
158164
export const Leaves = [
159165
t.Unknown, t.Never, t.Any, t.Void, t.Undefined, t.Null, t.Symbol, t.BigInt, t.Boolean, t.Number, t.String

packages/schema-core/src/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ t.Functor = Functor
104104
t.fold = fold
105105
t.unfold = unfold
106106
t.is = is
107+
t.inline = inline

0 commit comments

Comments
 (0)