BigDecimalFromStringType-level representation of BigDecimalFromString.
export interface BigDecimalFromString extends interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<BigDecimal, String> {
readonly "Rebuild": BigDecimalFromString
}
/**
* Schema that parses a string into a `BigDecimal`.
*
* **When to use**
*
* Use to parse decimal or exponent-notation strings into arbitrary-precision
* BigDecimal values while encoding them back to strings.
*
* **Details**
*
* Decoding:
* - A `string` is decoded with `BigDecimal.fromString`.
*
* Encoding:
* - A `BigDecimal` is encoded with `BigDecimal.format`.
*
* **Gotchas**
*
* An empty string decodes as zero.
*
* @see {@link BigDecimal} for validating values that are already BigDecimal values
* @see {@link BigIntFromString} for parsing base-10 integer strings into bigint values
* @see {@link NumberFromString} for parsing JavaScript number strings
*
* @category BigDecimal
* @since 4.0.0
*/
export const const BigDecimalFromString: BigDecimalFromStringconst BigDecimalFromString: {
Rebuild: BigDecimalFromString;
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
ast: Ast;
annotate: (annotations: Annotations.Bottom<BigDecimal_.BigDecimal, readonly []>) => BigDecimalFromString;
annotateKey: (annotations: Annotations.Key<BigDecimal_.BigDecimal>) => BigDecimalFromString;
check: (checks_0: SchemaAST.Check<BigDecimal_.BigDecimal>, ...checks: Array<SchemaAST.Check<BigDecimal_.BigDecimal>>) => BigDecimalFromString;
rebuild: (ast: SchemaAST.Declaration) => BigDecimalFromString;
make: (input: BigDecimal_.BigDecimal, options?: MakeOptions) => BigDecimal_.BigDecimal;
makeOption: (input: BigDecimal_.BigDecimal, options?: MakeOptions) => Option_.Option<BigDecimal_.BigDecimal>;
makeEffect: (input: BigDecimal_.BigDecimal, options?: MakeOptions) => Effect.Effect<BigDecimal_.BigDecimal, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
BigDecimalFromString
.
Schema that parses a string into a BigDecimal.
When to use
Use to parse decimal or exponent-notation strings into arbitrary-precision
BigDecimal values while encoding them back to strings.
Details
Decoding:
- A
string is decoded with BigDecimal.fromString.
Encoding:
- A
BigDecimal is encoded with BigDecimal.format.
Gotchas
An empty string decodes as zero.
BigDecimalFromString: BigDecimalFromString = const BigDecimalString: Stringconst BigDecimalString: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
BigDecimalString.pipe(
function decodeTo<BigDecimal, Constraint, never, never>(to: BigDecimal, transformation: {
readonly decode: SchemaGetter.Getter<BigDecimal_.BigDecimal, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, BigDecimal_.BigDecimal, never>;
}): (from: Constraint) => decodeTo<BigDecimal, Constraint, never, never> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(const BigDecimal: BigDecimalconst BigDecimal: {
Rebuild: BigDecimal;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<BigDecimal_.BigDecimal, readonly []>) => BigDecimal;
annotateKey: (annotations: Annotations.Key<BigDecimal_.BigDecimal>) => BigDecimal;
check: (checks_0: SchemaAST.Check<BigDecimal_.BigDecimal>, ...checks: Array<SchemaAST.Check<BigDecimal_.BigDecimal>>) => BigDecimal;
rebuild: (ast: SchemaAST.Declaration) => BigDecimal;
make: (input: BigDecimal_.BigDecimal, options?: MakeOptions) => BigDecimal_.BigDecimal;
makeOption: (input: BigDecimal_.BigDecimal, options?: MakeOptions) => Option_.Option<BigDecimal_.BigDecimal>;
makeEffect: (input: BigDecimal_.BigDecimal, options?: MakeOptions) => Effect.Effect<BigDecimal_.BigDecimal, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
BigDecimal
.
Schema for BigDecimal values.
When to use
Use when you already have Effect decimal instances and need schema
validation, formatting, equivalence, and JSON string serialization.
Details
Default JSON serializer:
- encodes
BigDecimal as a string
BigDecimal, import SchemaTransformationSchemaTransformation.const bigDecimalFromString: Transformation<
BigDecimal.BigDecimal,
string
>
const bigDecimalFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, BigDecimal_.BigDecimal, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, BigDecimal_.BigDecimal, RD2, RE2>) => SchemaTransformation.Transformation<T2, string, RD2, RE2>;
}
Decodes a string into a BigDecimal and encodes a BigDecimal back to
its string representation.
When to use
Use when you need a schema transformation to parse decimal number strings
from APIs or user input.
Details
Decoding calls BigDecimal.fromString(s) and fails with InvalidValue if
the string is not a valid BigDecimal representation. Encoding returns
BigDecimal.format(bd).
bigDecimalFromString)
)