Skip to content

Commit

Permalink
Test for performance comparison; error channels don't extend AnyError.
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Jun 6, 2021
1 parent 045f840 commit 747ce7c
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 231 deletions.
4 changes: 2 additions & 2 deletions packages/schema/src/Arbitrary/_arbitrary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const cache = new WeakMap()

function for_<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/Collect/_collect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ const cache = new WeakMap()

export function collectAnnotationsFor<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/Constructor/_constructor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ const cache = new WeakMap()

function constructorFor<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/Encoder/_encoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const cache = new WeakMap()

function encoderFor<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/Guard/_guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const cache = new WeakMap()

function guardFor<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/Parser/_parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ const cache = new WeakMap()

function parserFor<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/_api/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { withDefaults } from "./withDefaults"
export const arrayIdentifier = S.makeAnnotation<{ self: S.SchemaUPI }>()

export function array<
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
5 changes: 2 additions & 3 deletions packages/schema/src/_api/brand.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// tracing: off
import type * as MO from "../_schema"
import type { ApiSelfType, Schema } from "../_schema/schema"
import type { DefaultSchema } from "./withDefaults"
import { withDefaults } from "./withDefaults"

export function brand<B>() {
return <
ParserInput,
ParserError extends MO.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends MO.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
8 changes: 4 additions & 4 deletions packages/schema/src/_api/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const fromChunkIdentifier = makeAnnotation<{ self: S.SchemaAny }>()

export function fromChunk<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down Expand Up @@ -95,10 +95,10 @@ export function fromChunk<
export const chunkIdentifier = makeAnnotation<{ self: S.SchemaAny }>()

export function chunk<
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
15 changes: 7 additions & 8 deletions packages/schema/src/_api/condemn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as T from "@effect-ts/core/Effect"
import * as E from "@effect-ts/core/Either"
import { Case } from "@effect-ts/system/Case"

import type { AnyError } from "../_schema"
import { drawError } from "../_schema"
import type { These } from "../These"

Expand Down Expand Up @@ -33,32 +32,32 @@ export class CondemnException extends Case<{ readonly message: string }> {
export class ThrowableCondemnException extends Error {
readonly _tag = "CondemnException"

constructor(readonly error: AnyError) {
super(drawError(error))
constructor(readonly error: unknown) {
super(drawError(error as any)) // TODO
}
}

export function condemnFail<X, A>(self: (a: X) => These<AnyError, A>) {
export function condemnFail<X, A>(self: (a: X) => These<unknown, A>) {
return (a: X, __trace?: string) =>
T.fromEither(() => {
const res = self(a).effect
if (res._tag === "Left") {
return E.left(new CondemnException({ message: drawError(res.left) }))
return E.left(new CondemnException({ message: drawError(res.left as any) }))
}
const warn = res.right.get(1)
if (warn._tag === "Some") {
return E.left(new CondemnException({ message: drawError(warn.value) }))
return E.left(new CondemnException({ message: drawError(warn.value as any) }))
}
return E.right(res.right.get(0))
}, __trace)
}

export function condemnDie<X, A>(self: (a: X) => These<AnyError, A>) {
export function condemnDie<X, A>(self: (a: X) => These<unknown, A>) {
const orFail = condemnFail(self)
return (a: X, __trace?: string) => T.orDie(orFail(a, __trace))
}

export function unsafe<X, A>(self: (a: X) => These<AnyError, A>) {
export function unsafe<X, A>(self: (a: X) => These<unknown, A>) {
return (a: X) => {
const res = self(a).effect
if (res._tag === "Left") {
Expand Down
34 changes: 10 additions & 24 deletions packages/schema/src/_api/intersect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ export const intersectIdentifier =
S.makeAnnotation<{ self: S.SchemaUPI; that: S.SchemaUPI }>()

export function intersect_<
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api,
ThatParserError extends S.AnyError,
ThatParserError,
ThatParsedShape,
ThatConstructorInput,
ThatConstructorError extends S.AnyError,
ThatConstructorError,
ThatEncoded,
ThatApi
>(
Expand Down Expand Up @@ -242,10 +242,10 @@ export function intersect_<
}

export function intersect<
ThatParserError extends S.AnyError,
ThatParserError,
ThatParsedShape,
ThatConstructorInput,
ThatConstructorError extends S.AnyError,
ThatConstructorError,
ThatEncoded,
ThatApi
>(
Expand All @@ -258,14 +258,7 @@ export function intersect<
ThatEncoded,
ThatApi
>
): <
ParserError extends S.AnyError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
Encoded,
Api
>(
): <ParserError, ParsedShape, ConstructorInput, ConstructorError, Encoded, Api>(
self: S.Schema<
unknown,
ParserError,
Expand All @@ -288,10 +281,10 @@ export function intersect<
}

export function intersectLazy<
ThatParserError extends S.AnyError,
ThatParserError,
ThatParsedShape,
ThatConstructorInput,
ThatConstructorError extends S.AnyError,
ThatConstructorError,
ThatEncoded,
ThatApi
>(
Expand All @@ -305,14 +298,7 @@ export function intersectLazy<
ThatApi
>
) {
return <
ParserError extends S.AnyError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
Encoded,
Api
>(
return <ParserError, ParsedShape, ConstructorInput, ConstructorError, Encoded, Api>(
self: S.Schema<
unknown,
ParserError,
Expand Down
6 changes: 3 additions & 3 deletions packages/schema/src/_api/lazy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { AnyError, Schema } from "../_schema"
import type { Schema } from "../_schema"
import { SchemaLazy } from "../_schema"
import type { DefaultSchema } from "./withDefaults"
import { withDefaults } from "./withDefaults"

export function lazy<
ParserInput,
ParserError extends AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/_api/nonEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export const nonEmptyIdentifier = S.makeAnnotation<{ self: S.SchemaAny }>()

export function nonEmpty<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape extends { length: number },
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/_api/nullable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export const nullableIdentifier = S.makeAnnotation<{ self: S.SchemaAny }>()

export function nullable<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/_api/positive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const positiveIdentifier = S.makeAnnotation<{ self: S.SchemaAny }>()

export function positive<
ParserInput,
ParserError extends S.AnyError,
ParserError,
ParsedShape extends number,
ConstructorInput,
ConstructorError extends S.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/_api/refinement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const refinementIdentifier =
error: (value: unknown) => unknown
}>()

export function refinement<E extends S.AnyError, NewParsedShape>(
export function refinement<E, NewParsedShape>(
refinement: Refinement<unknown, NewParsedShape>,
error: (value: unknown) => E
): DefaultSchema<
Expand Down
2 changes: 0 additions & 2 deletions packages/schema/src/_api/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ export function union<Props extends Record<PropertyKey, S.SchemaUPI>>(
)
)
} else {
// @ts-expect-error
return Th.mapError_(parsers[tag.value.index[u[tag.value.key]]](u), (e) =>
S.compositionE(
Chunk.single(
Expand All @@ -296,7 +295,6 @@ export function union<Props extends Record<PropertyKey, S.SchemaUPI>>(
const res = parser(u)

if (res.effect._tag === "Right") {
// @ts-expect-error
return Th.mapError_(res, (e) =>
S.compositionE(Chunk.single(S.nextE(S.unionE(Chunk.single(S.memberE(k, e))))))
)
Expand Down
9 changes: 1 addition & 8 deletions packages/schema/src/_api/withDefaultConstructorField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ export function withDefaultConstructorField<
>(
key: Key,
value: Lazy<ConstructorInput[Key]>
): <
ParserInput,
ParserError extends S.AnyError,
ParsedShape,
ConstructorError extends S.AnyError,
Encoded,
Api
>(
): <ParserInput, ParserError, ParsedShape, ConstructorError, Encoded, Api>(
self: S.Schema<
ParserInput,
ParserError,
Expand Down
12 changes: 6 additions & 6 deletions packages/schema/src/_api/withDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { unsafe } from "./condemn"

export interface SchemaDefaultSchema<
ParserInput,
ParserError extends MO.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends MO.AnyError,
ConstructorError,
Encoded,
Api
> extends Schema<
Expand Down Expand Up @@ -59,10 +59,10 @@ export interface SchemaDefaultSchema<

export type DefaultSchema<
ParserInput,
ParserError extends MO.AnyError,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError extends MO.AnyError,
ConstructorError,
Encoded,
Api
> = SchemaDefaultSchema<
Expand All @@ -89,9 +89,9 @@ type CarryFromApi<Api> = UnionToIntersection<
export function withDefaults<
ParserInput,
ParsedShape,
ParserError extends MO.AnyError,
ParserError,
ConstructorInput,
ConstructorError extends MO.AnyError,
ConstructorError,
Encoded,
Api
>(
Expand Down
Loading

0 comments on commit 747ce7c

Please sign in to comment.